zhangguidong 2 年之前
父節點
當前提交
fff14d1040

+ 15 - 5
application/api/controller/Pay.php

@@ -571,7 +571,7 @@ class Pay extends Controller
      * 畅联支付
      */
     public function changlianRechargeOrderNotify(){
-        file_put_contents("./callback_log.txt", json_encode($_POST));
+        file_put_contents("changlian_pay_sing.txt", json_encode($_POST));
 //商户名称
         $appid  = $_POST['appid'];
 //支付时间戳
@@ -603,14 +603,24 @@ class Pay extends Controller
         ];
 
 //第一步,检测商户appid否一致
-        if ($appid != '你的商户appid') exit('error:appid');
+        if ($appid != '1058182') exit('error:appid');
 //第二步,验证签名是否一致
-        if (verifySign($data,'商户密钥') == $sign){
-            echo 'success';
+        if (verifySign($data,'MHBRLkI4vFaAhLgdPkjp3QNMqsNrz8al') == $sign){
+            if($data['callbacks']=='CODE_SUCCESS'){
+                $return = $this->dealRechargeData($out_trade_no,'changlian');
+                if ($return){
+                    return 'success';
+                }else{
+                    return false;
+                }
+            } else {
+                return false;
+            }
         } else{
-            exit('error:sign');
+            return false;
         }
     }
+
     /**
      * 充值余额处理数据库信息
      * @param $result

+ 1 - 1
application/api/controller/UserCenter.php

@@ -1189,7 +1189,7 @@ class UserCenter extends Base
                 $obj = new Changlian();
                 $notifyUrl = 'https://'.$_SERVER['SERVER_NAME'].'/index.php/api/Pay/ChanglianRechargeOrderNotify';//回调地址
                 $returnUrl = 'https://'.$_SERVER['SERVER_NAME'].'/web/h5';
-                $result = $obj->changlian_pay($body,$order_no,$total_fee,'',$notifyUrl,$returnUrl);
+                $result = $obj->changlian_pay($total_fee,$order_no,$notifyUrl,$returnUrl);
                 if(empty($result)){
                     $com = false;
                 }

+ 46 - 0
application/common.php

@@ -1391,3 +1391,49 @@ function checkBoxCollection($coll_id){
         }
     }
 }
+
+function getSign($secret, $data)
+{
+    if(isset($data['sign'])){
+        unset($data['sign']);
+    }
+    // 去空
+    $data = array_filter($data);
+    //签名步骤一:按字典序排序参数
+    ksort($data);
+    // var_dump($data);
+    $string_a = http_build_query($data);
+    $string_a = urldecode($string_a);
+
+    //签名步骤二:在string后加入mch_key
+    $string_sign_temp = $string_a . "&key=" . $secret;
+    // var_dump($string_sign_temp);
+    //签名步骤三:MD5加密
+    $sign = md5($string_sign_temp);
+
+    // 签名步骤四:所有字符转为大写
+    $result = strtoupper($sign);
+    // var_dump($result);
+    return $result;
+}
+
+
+/**
+ * @Note   验证签名
+ * @param $data
+ * @param $orderStatus
+ * @return bool
+ */
+function verifySign($data, $secret) {
+    // 验证参数中是否有签名
+    if (!isset($data['sign']) || !$data['sign']) {
+        return false;
+    }
+    // 要验证的签名串
+    $sign = $data['sign'];
+    unset($data['sign']);
+    // 生成新的签名、验证传过来的签名
+    $sign2 = getSign($secret, $data);
+
+    return $sign2;
+}

+ 7 - 32
application/common/library/Changlian.php

@@ -4,7 +4,7 @@ namespace app\common\library;
 
 class Changlian
 {
-    public function changlian_pay(){
+    public function changlian_pay($money,$order_no,$notifyUrl,$returnUrl){
         //请求支付地址
         $api = 'https://api2.payunk.com/index/unifiedorder?format=json';
 //商户appid->到平台首页自行复制粘贴
@@ -14,17 +14,17 @@ class Changlian
         $app_key = 'MHBRLkI4vFaAhLgdPkjp3QNMqsNrz8al';
 
 //订单号码,发起订单时带的订单信息,一般为用户名,交易号,等字段信息
-        $out_trade_no = date("YmdHis") . mt_rand(10000, 99999);
+        $out_trade_no = $order_no;
 //支付类型
         $pay_type = 'partnerJs';
 //支付金额
-        $amount = sprintf("%.2f",0.01);
+        $amount = sprintf("%.2f",$money);
 //异步通知接口url->用作于接收成功支付后回调请求
-        $callback_url = 'https://api2.payunk.com/callback_demo.php';
+        $callback_url = $notifyUrl;
 //支付成功后自动跳转url
-        $success_url = 'https://api2.payunk.com';
+        $success_url = $returnUrl;
 //支付失败或者超时后跳转url
-        $error_url = 'https://api2.payunk.com';
+        $error_url = $returnUrl;
 //版本号
         $version = 'v1.0';
 //用户网站的请求支付的额外信息,请严格对接文档填写参数
@@ -43,7 +43,7 @@ class Changlian
         ];
 
 //拿APPKEY与请求参数进行签名
-        $sign = $this->getSign($app_key, $data);
+        $sign = getSign($app_key, $data);
         $data['sign']=$sign;
 
         $post_data = json_encode($data,320);
@@ -68,29 +68,4 @@ class Changlian
 //        print_r($output);die;
         return $output;
     }
-    public function getSign($secret, $data){
-            if(isset($data['sign'])){
-                unset($data['sign']);
-            }
-            // 去空
-            $data = array_filter($data);
-            //签名步骤一:按字典序排序参数
-            ksort($data);
-            // var_dump($data);
-            $string_a = http_build_query($data);
-            $string_a = urldecode($string_a);
-
-            //签名步骤二:在string后加入mch_key
-            $string_sign_temp = $string_a . "&key=" . $secret;
-            // var_dump($string_sign_temp);
-            //签名步骤三:MD5加密
-            $sign = md5($string_sign_temp);
-
-            // 签名步骤四:所有字符转为大写
-            $result = strtoupper($sign);
-            // var_dump($result);
-            return $result;
-
-    }
-
 }