cqpCow 1 年間 前
コミット
621059c89c
2 ファイル変更61 行追加11 行削除
  1. 58 9
      app/Service/CodeService.php
  2. 3 2
      app/Service/FinanceService.php

+ 58 - 9
app/Service/CodeService.php

@@ -39,7 +39,7 @@ class CodeService extends Service
 
         //发送验证码到手机 TODO
         list($status,$msg) = $this->sendCode($code);
-        if(! $status) return [false,'发送验证码失败!'];
+        if(! $status) return [false,$msg];
 
         //成功后 缓存code 60s
         Cache::add($cacheKey,$code,60);
@@ -60,9 +60,23 @@ class CodeService extends Service
         //获取验证码
         $code = $this->createCode();
 
-        //发送验证码到手机 TODO
-        list($status,$msg) = $this->sendCode($code);
-        if(! $status) return [false,'发送验证码失败!'];
+        //获取金额数据
+        $finance = (new FinanceService())->getData($data['id']);
+        if(empty($finance)) return [false,'未找到出账数据!'];
+
+        $send = [
+            "code"=> $code,
+            "type"=> 2,
+            "account" => $finance['account'],
+            "bankAccount" => $finance['finance_account_name'],
+            "ifsc" => $finance['ifsc'],
+            "amount" => $finance['amount'],
+        ];
+        $send['sign'] = $this->sign($send);
+
+        //发送验证码到
+        list($status,$msg) = $this->sendCode($send);
+        if(! $status) return [false, $msg];
 
         //成功后 缓存code 60s
         Cache::add($cacheKey,$code,60);
@@ -70,8 +84,27 @@ class CodeService extends Service
         return [true,''];
     }
 
-    //发送验证码  TODO
-    public function sendCode($code){
+    //加密
+    public function sign($data){
+        $str = [];
+        sort($data);
+        foreach ($data as $k=>$v){
+            $str[] = $k.'='.$v;
+        }
+
+        $vaild = implode(',',$str).'doTAKtnpiG';
+        return md5($vaild);
+    }
+
+    //发送验证码
+    public function sendCode($send){
+        $url = "https://api2.indiacashpayment.in/sendTelegramCode";
+        $result = $this->curlURL($url,$send);
+
+        if($result['status'] == 201){
+            return [false, $result['msg']];
+        }
+
         return [true,''];
     }
 
@@ -104,9 +137,25 @@ class CodeService extends Service
         return [false,'验证码不存在!'];
     }
 
-
-
-
+    public function curlURL($url,$data){
+        $data = json_encode($data);
+        $header[] = "Content-Type:application/json";
+        $ch=curl_init($url);
+        curl_setopt($ch,CURLOPT_POST,1);
+        curl_setopt($ch,CURLOPT_POSTFIELDS,$data);
+        curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
+        curl_setopt($ch,CURLOPT_HTTPHEADER,$header);
+        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
+        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
+        $response=curl_exec($ch);
+        file_put_contents('charge.txt',$response.PHP_EOL,8);
+        $response=json_decode($response,true);
+
+        if(curl_errno($ch) ){
+            sc(curl_error($ch));
+        }
+        return $response;
+    }
 
 
     //------------------暂时用不到下面------------------------//

+ 3 - 2
app/Service/FinanceService.php

@@ -46,7 +46,8 @@ class FinanceService extends Service
             ->where('a.del_time',0)
             ->where('b.del_time',0)
             ->select('a.finance_account_name','a.account','a.ifsc','a.crt_time','b.id','b.amount','b.status','b.confirm_time')
-            ->orderBy('a.id','desc');
+            ->ordertBy('b.status','asc')
+            ->orderBy('a.id','asc');
 
         if(! empty($data['finance_account_name'])) $model->where('a.finance_account_name', 'LIKE', '%'.$data['finance_account_name'].'%');
         if(! empty($data['account'])) $model->where('a.account', 'LIKE', '%'.$data['account'].'%');
@@ -158,7 +159,7 @@ class FinanceService extends Service
         return [true, ''];
     }
 
-    protected function getData($id){
+    public function getData($id){
         if(empty($id)) return [];
 
         $model = FinanceDetail::from('finance_detail as a')