Procházet zdrojové kódy

refill third and card info

ayHaru před 4 roky
rodič
revize
bb4e5e902a

+ 6 - 0
data/model/thrid_refill.model.php

@@ -36,6 +36,12 @@ class thrid_refillModel extends Model
 
     public function addExt($data)
     {
+        return $this->table('refill_third')->insert($data);
+    }
 
+    public function refill_third_edit($order_id,$data)
+    {
+        return $this->table('refill_third')->where(['order_id' => $order_id])->update($data);
     }
+
 }

+ 8 - 2
helper/refill/RefillBase.php

@@ -325,8 +325,14 @@ class RefillBase
 
                 if($card_type == mtopcard\ThirdRefillCard) {
                     $thrid_refill = Model('thrid_refill');
-                    $ext = ['order_id' => $order_id,'order'];
-                    $thrid_refill->add_ext($ext);
+                    $ext = ['order_id' => $order_id,
+                        'order_sn' => $order_sn,
+                        'account_type' => $third_params['third_card_type'],
+                        'quantity' => $quantity,
+                        'user_account' => $card_no,
+                        'pcode' => $third_params['product_code']
+                    ];
+                    $thrid_refill->addExt($ext);
                 }
 
                 if(!$this->pay_completed($order_sn)) {

+ 8 - 0
helper/refill/api/lingzh/sctongqian/RefillCallBack.php

@@ -36,6 +36,14 @@ class RefillCallBack implements refill\IRefillCallBack
 
         if ($status === 2) {
             $result = $this->rsa_decode($params['CardInfo']);
+            if (empty($result)) {
+                $data['ret_state'] = 2;
+                $data['card_info'] = '回调解密,解密失败';
+            } else {
+                $data['ret_state'] = 1;
+                $data['card_info'] = $result;
+            }
+            Model('refill_order')->refill_third_edit($order_id, $data);
             return [$order_id, true, false,true];
         }
         elseif ($status === 3) {

+ 27 - 13
helper/refill/api/lingzh/sctongqian/RefillPhone.php

@@ -71,6 +71,9 @@ class RefillPhone extends refill\IRefillPhone
         $order_sn = $params['order_sn'];
         $goods_id = intval($params['goods_id']);
         $product_code = $this->getProductCode($goods_id,$params['product_code']);
+
+        Model('thrid_refill')->refill_third_edit($params['order_id'], ['chcode' => $product_code]);
+
         $quantity = intval($params['quantity']);
 
         $params = $this->req_params($order_sn,$product_code,$quantity);
@@ -105,6 +108,9 @@ class RefillPhone extends refill\IRefillPhone
         $order_sn = $params['order_sn'];
         $goods_id = intval($params['goods_id']);
         $product_code = $this->getProductCode($goods_id,$params['product_code']);
+
+        Model('thrid_refill')->refill_third_edit($params['order_id'], ['chcode' => $product_code]);
+
         $quantity = intval($params['quantity']);
 
         $params = $this->req_params($order_sn,$product_code,$quantity);
@@ -146,14 +152,14 @@ class RefillPhone extends refill\IRefillPhone
         $resp = http_request(config::QUERY_URL, $params);
 
         if (empty($resp)) {
-            return [false, '网络错误', []];
+            return [false, '网络错误'];
         }
         else
         {
             Log::record($resp, Log::DEBUG);
             $resp = json_decode($resp, true);
             if (empty($resp)) {
-                return [false, '网络错误', []];
+                return [false, '网络错误'];
             }
             elseif ($resp['Code'] == 999)
             {
@@ -161,12 +167,15 @@ class RefillPhone extends refill\IRefillPhone
                 $result = [];
                 if ($status === 2) {
                     if(!empty($resp['Data']['CardData'])) {
-                        $cards = $this->rsa_decode($resp['Data']['CardData']);
-                        $cards = json_decode($cards, true);
-                        foreach ($cards as $card) {
-                            $result[] = $card;
+                        $result = $this->rsa_decode($resp['Data']['CardData']);
+                        if (empty($result)) {
+                            $data['ret_state'] = 2;
+                            $data['card_info'] = '查询接口,解密失败';
+                        } else {
+                            $data['ret_state'] = 1;
+                            $data['card_info'] = $result;
                         }
-                        //需返回卡密信息
+                        Model('refill_order')->refill_third_edit($refill_info['order_id'], $data);
                     }
                     $order_state = ORDER_STATE_SUCCESS;
                 } elseif ($status === 3) {
@@ -176,21 +185,26 @@ class RefillPhone extends refill\IRefillPhone
                 } else {
                     return [false, $resp['Message'], $result];
                 }
-                return [true, $order_state, $result];
+                return [true, $order_state];
             }
             else
             {
-                return [false, $resp['Message'], []];
+                return [false, $resp['Message']];
             }
         }
     }
 
     private function rsa_decode($encrypted)
     {
-        $private_key = config::PRIVATE_KEY;
-        //使用私钥解密数据
-        openssl_private_decrypt(base64_decode($encrypted), $decrypted,$private_key);
-        return $decrypted;
+        $ret = openssl_private_decrypt(base64_decode($encrypted), $decrypted, config::PRIVATE_KEY);
+        if ($ret) {
+            $result = json_decode($decrypted, true);
+            return $result;
+        } else {
+            $err = openssl_error_string();
+            Log::record("sctongqian callback openssl_private_decrypt error={$err}", Log::ERR);
+            return false;
+        }
     }
 
     private function sign($params)