|
|
@@ -599,15 +599,73 @@ class WechatService
|
|
|
$total_fee = bcmul($total_fee, 100, 0);
|
|
|
$timestamp=time();
|
|
|
$version = '1.0';
|
|
|
- $order = array_merge(compact('out_trade_no', 'total_fee', 'attach', 'body', 'detail', 'trade_type', 'openid','contract_code','plan_id','spbill_create_ip','contract_display_account','timestamp','version'), $options);
|
|
|
- if ($order['detail'] == '') unset($order['detail']);
|
|
|
- $order['contract_notify_url']=Request::instance()->domain() . "/api/wechat/notify/" . $cid;
|
|
|
- $result = self::payment(false, $cid)->contract->web(
|
|
|
- $order
|
|
|
- );
|
|
|
+ // 微信支付配置参数
|
|
|
+ $mch_id = "1623907696"; // 替换为你的商户号
|
|
|
+ $key = "1wm55KpF5tgZFW1TYs6TBX9MWBpI5FmT"; // 替换为你的API密钥
|
|
|
+
|
|
|
+// 请求参数(来自示例)
|
|
|
+ $params = [
|
|
|
+ 'out_trade_no' => 'yj175029625305847308',
|
|
|
+ 'total_fee' => '1',
|
|
|
+ 'attach' => 'lave',
|
|
|
+ 'body' => '博爱送万家(爱心家庭包)',
|
|
|
+ 'trade_type' => 'JSAPI',
|
|
|
+ 'openid' => 'o1Xu36OxyNugoMFVP8o0upKB3tKg',
|
|
|
+ 'contract_code' => 'qy175029625306023753',
|
|
|
+ 'plan_id' => '189172',
|
|
|
+ 'spbill_create_ip' => '47.97.158.164',
|
|
|
+ 'contract_display_account' => '昔拉',
|
|
|
+ 'timestamp' => 1750296253,
|
|
|
+ 'version' => '1.0',
|
|
|
+ 'contract_notify_url' => 'http://red.igxys.com/api/wechat/notify/12',
|
|
|
+ 'appid' => 'wx5681205d1ef4d9d3',
|
|
|
+ 'mch_id' => $mch_id, // 添加商户号
|
|
|
+ ];
|
|
|
+
|
|
|
+// 步骤1:参数按ASCII排序
|
|
|
+ ksort($params);
|
|
|
+
|
|
|
+// 步骤2:构建待签名字符串
|
|
|
+ $stringA = "";
|
|
|
+ foreach ($params as $k => $v) {
|
|
|
+ $stringA .= $k . '=' . $v . '&';
|
|
|
+ }
|
|
|
+ $stringSignTemp = $stringA . 'key=' . $key; // 拼接API密钥
|
|
|
+
|
|
|
+// 步骤3:生成HMAC-SHA256签名
|
|
|
+ $sign = strtoupper(hash_hmac('sha256', $stringSignTemp, $key));
|
|
|
+ $params['sign'] = $sign; // 添加签名到请求参数
|
|
|
+
|
|
|
+// 步骤4:构建GET请求URL(对参数值进行URL编码)
|
|
|
+ $queryString = "";
|
|
|
+ foreach ($params as $k => $v) {
|
|
|
+ $queryString .= $k . '=' . urlencode($v) . '&';
|
|
|
+ }
|
|
|
+ $url = 'https://api.mch.weixin.qq.com/papay/entrustweb?' . rtrim($queryString, '&');
|
|
|
+
|
|
|
+// 步骤5:发送CURL请求
|
|
|
+ $ch = curl_init();
|
|
|
+ curl_setopt($ch, CURLOPT_URL, $url);
|
|
|
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
|
|
+ curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true); // 生产环境建议验证SSL
|
|
|
+ curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
|
|
|
+
|
|
|
+ $response = curl_exec($ch);
|
|
|
+// if (curl_errno($ch)) {
|
|
|
+// echo 'CURL Error: ' . curl_error($ch);
|
|
|
+// } else {
|
|
|
+// echo "Response:\n" . $response;
|
|
|
+// }
|
|
|
+
|
|
|
+// $order = array_merge(compact('out_trade_no', 'total_fee', 'attach', 'body', 'detail', 'trade_type', 'openid','contract_code','plan_id','spbill_create_ip','contract_display_account','timestamp','version'), $options);
|
|
|
+// if ($order['detail'] == '') unset($order['detail']);
|
|
|
+// $order['contract_notify_url']=Request::instance()->domain() . "/api/wechat/notify/" . $cid;
|
|
|
+// $result = self::payment(false, $cid)->contract->web(
|
|
|
+// $order
|
|
|
+// );
|
|
|
// var_dump($result);die();
|
|
|
- @file_put_contents("quanju3.txt", json_encode($result) . "-签约返回结果测试\r\n", 8);
|
|
|
- return $result;
|
|
|
+ @file_put_contents("quanju3.txt", json_encode($response) . "-签约返回结果测试\r\n", 8);
|
|
|
+ return $response;
|
|
|
}
|
|
|
/**
|
|
|
* 签约申请扣款
|