|
@@ -100,6 +100,7 @@ class Wechat extends Api
|
|
|
@file_put_contents("error.txt", $e->getFile() . '-', $e->getLine(), '-' . $e->getMessage());
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
/**
|
|
|
* 扣款服务
|
|
|
* @param Request $request
|
|
@@ -112,80 +113,81 @@ class Wechat extends Api
|
|
|
{
|
|
|
$price = intval($request->param('price'));
|
|
|
$uid = intval($request->param('uid'));
|
|
|
- $plan_id = WechatPlan::where('price',$price)->value('plan_id');
|
|
|
- $p_id = WechatPlan::where('price',$price)->value('id');
|
|
|
- $plan_id=11;
|
|
|
- $p_id=12;
|
|
|
-// try {
|
|
|
+ $plan_id = WechatPlan::where('price', $price)->value('plan_id');
|
|
|
+ $p_id = WechatPlan::where('price', $price)->value('id');
|
|
|
+ $plan_id = 11;
|
|
|
+ $p_id = 12;
|
|
|
+ try {
|
|
|
// $notify_url=Request::instance()->domain() . "/api/wechat/notify/" . $cid; //回调接口
|
|
|
- $app_id='wx5681205d1ef4d9d3';
|
|
|
- $mch_id ='1623907696';
|
|
|
- $sub_mch_id ='';
|
|
|
- $contract_code =$this->generateRandomString(12);
|
|
|
- $notify_url=Request::instance()->domain() . "/api/wechat/notify/" . 12; //回调接口 $cid 企业id
|
|
|
+ $app_id = 'wx5681205d1ef4d9d3';
|
|
|
+ $mch_id = '1623907696';
|
|
|
+ $sub_mch_id = '';
|
|
|
+ $contract_code = $this->generateRandomString(12);
|
|
|
+ $notify_url = Request::instance()->domain() . "/api/wechat/notify/" . 12; //回调接口 $cid 企业id
|
|
|
// $num = time() + mt_rand(10, 999999) . '' . substr($msec, 2, 3);//生成随机数
|
|
|
// $request_serial=$this->generateUniqueSerialNumber();
|
|
|
- $request_serial=WechatPlanRecord::where('is_signing',0)->order('request_serial desc')->value('request_serial');
|
|
|
- if (empty($request_serial)){
|
|
|
- $request_serial=100000;
|
|
|
- }else{
|
|
|
- $request_serial=$request_serial+1;
|
|
|
- }
|
|
|
- $contract_display_account='咸宁红十字';
|
|
|
- $timestamp=time();
|
|
|
- $version='1.0';
|
|
|
- $array = array(
|
|
|
- 'appid' => $app_id,
|
|
|
- 'mch_id' => $mch_id,
|
|
|
- 'plan_id' => $plan_id,
|
|
|
+ $request_serial = WechatPlanRecord::where('is_signing', 0)->order('request_serial desc')->value('request_serial');
|
|
|
+ if (empty($request_serial)) {
|
|
|
+ $request_serial = 100000;
|
|
|
+ } else {
|
|
|
+ $request_serial = $request_serial + 1;
|
|
|
+ }
|
|
|
+ $contract_display_account = '咸宁红十字';
|
|
|
+ $timestamp = time();
|
|
|
+ $version = '1.0';
|
|
|
+ $array = array(
|
|
|
+ 'appid' => $app_id,
|
|
|
+ 'mch_id' => $mch_id,
|
|
|
+ 'plan_id' => $plan_id,
|
|
|
// 'sub_mch_id' => $sub_mch_id,
|
|
|
- 'contract_code' => $contract_code,
|
|
|
- 'notify_url' => $notify_url,
|
|
|
- 'contract_display_account' => $contract_display_account,
|
|
|
- 'request_serial' => $request_serial,
|
|
|
- 'timestamp' => $timestamp,
|
|
|
- 'version' => $version,
|
|
|
+ 'contract_code' => $contract_code,
|
|
|
+ 'notify_url' => $notify_url,
|
|
|
+ 'contract_display_account' => $contract_display_account,
|
|
|
+ 'request_serial' => $request_serial,
|
|
|
+ 'timestamp' => $timestamp,
|
|
|
+ 'version' => $version,
|
|
|
|
|
|
- );
|
|
|
+ );
|
|
|
|
|
|
|
|
|
- ksort($array);
|
|
|
- $xml='';
|
|
|
- foreach ($array as $key => $value){
|
|
|
- $xml=$xml.$key.'='.$value.'&';
|
|
|
- }
|
|
|
- $xml=substr($xml, 0, -1);
|
|
|
- @file_put_contents("quanju.txt", json_encode($xml)."-签约内容\r\n", 8);
|
|
|
- $sign=$this->md5_sign($xml,'192006250b4c09247ec02edce69f6a2d');
|
|
|
- @file_put_contents("quanju.txt", $sign."-签名\r\n", 8);
|
|
|
- $url='https://api.mch.weixin.qq.com/papay/entrustweb?'.$xml.'&sign='. $sign;
|
|
|
- @file_put_contents("quanju.txt", $url."-链接\r\n", 8);
|
|
|
- var_dump($url);
|
|
|
+ ksort($array);
|
|
|
+ $xml = '';
|
|
|
+ foreach ($array as $key => $value) {
|
|
|
+ $xml = $xml . $key . '=' . $value . '&';
|
|
|
+ }
|
|
|
+ $xml = substr($xml, 0, -1);
|
|
|
+ @file_put_contents("quanju.txt", json_encode($xml) . "-签约内容\r\n", 8);
|
|
|
+ $sign = $this->md5_sign($xml, '192006250b4c09247ec02edce69f6a2d');
|
|
|
+ @file_put_contents("quanju.txt", $sign . "-签名\r\n", 8);
|
|
|
+ $url = 'https://api.mch.weixin.qq.com/papay/entrustweb?' . $xml . '&sign=' . $sign;
|
|
|
+ @file_put_contents("quanju.txt", $url . "-链接\r\n", 8);
|
|
|
+ var_dump($url);
|
|
|
// $response = $this->curl_get($url);
|
|
|
// $url=$this->OfficialAccountSigning($app_id,$mch_id,$plan_id,$contract_code,$request_serial,$contract_display_account,$notify_url,$version,$sign,$timestamp);
|
|
|
// @file_put_contents("quanju.txt", $response.'返回链接');
|
|
|
|
|
|
- WechatPlanRecord::create([
|
|
|
- 'uid' => $uid,
|
|
|
- 'plan_id' => $p_id,
|
|
|
- 'price' => $price,
|
|
|
- 'is_signing' => 0,
|
|
|
- 'request_serial' => $request_serial,
|
|
|
- 'contract_code' => $contract_code,
|
|
|
- 'contract_display_account' => $contract_display_account,
|
|
|
- 'createtime' => time(),
|
|
|
- 'cid' => 12,
|
|
|
- 'wechat_plan_id' => $plan_id,
|
|
|
- ]);
|
|
|
- die();
|
|
|
- return 1;
|
|
|
-// } catch (Exception $e) {
|
|
|
-// var_dump($e->getMessage());
|
|
|
-// @file_put_contents("error.txt", $e->getFile() . '-', $e->getLine(), '-' . $e->getMessage());
|
|
|
-// }
|
|
|
+ WechatPlanRecord::create([
|
|
|
+ 'uid' => $uid,
|
|
|
+ 'plan_id' => $p_id,
|
|
|
+ 'price' => $price,
|
|
|
+ 'is_signing' => 0,
|
|
|
+ 'request_serial' => $request_serial,
|
|
|
+ 'contract_code' => $contract_code,
|
|
|
+ 'contract_display_account' => $contract_display_account,
|
|
|
+ 'createtime' => time(),
|
|
|
+ 'cid' => 12,
|
|
|
+ 'wechat_plan_id' => $plan_id,
|
|
|
+ ]);
|
|
|
+ die();
|
|
|
+ return 1;
|
|
|
+ } catch (Exception $e) {
|
|
|
+ var_dump($e->getMessage());
|
|
|
+ @file_put_contents("error.txt", $e->getFile() . '-', $e->getLine(), '-' . $e->getMessage());
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
- public function generateRandomString($length) {
|
|
|
+ public function generateRandomString($length)
|
|
|
+ {
|
|
|
$characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
|
|
|
$charactersLength = strlen($characters);
|
|
|
$randomString = '';
|
|
@@ -194,8 +196,10 @@ class Wechat extends Api
|
|
|
}
|
|
|
return $randomString;
|
|
|
}
|
|
|
+
|
|
|
// 生成唯一序列号
|
|
|
- public function generateUniqueSerialNumber() {
|
|
|
+ public function generateUniqueSerialNumber()
|
|
|
+ {
|
|
|
// 使用uniqid生成一个唯一ID,并去除前缀的'0'
|
|
|
$uniqueId = ltrim(uniqid('', true), '0');
|
|
|
|
|
@@ -237,6 +241,7 @@ class Wechat extends Api
|
|
|
return $content;
|
|
|
|
|
|
}
|
|
|
+
|
|
|
public function curl_get(string $url, $timeout = 100)
|
|
|
{
|
|
|
// if (!empty($name)) {
|
|
@@ -256,16 +261,18 @@ class Wechat extends Api
|
|
|
|
|
|
$content = curl_exec($ch);
|
|
|
curl_close($ch);
|
|
|
- $content = json_decode($content,true);
|
|
|
+ $content = json_decode($content, true);
|
|
|
// $content = (array)$content;
|
|
|
// var_dump($content);
|
|
|
return $content;
|
|
|
}
|
|
|
- public function md5_sign($data, $key){
|
|
|
- $stringSignTemp=$data."&key=$key"; //注:key为商户平台设置的密钥key
|
|
|
|
|
|
- $sign=MD5($stringSignTemp); //MD5加密
|
|
|
- $sign=strtoupper($sign); //大写
|
|
|
+ public function md5_sign($data, $key)
|
|
|
+ {
|
|
|
+ $stringSignTemp = $data . "&key=$key"; //注:key为商户平台设置的密钥key
|
|
|
+
|
|
|
+ $sign = MD5($stringSignTemp); //MD5加密
|
|
|
+ $sign = strtoupper($sign); //大写
|
|
|
return $sign;
|
|
|
}
|
|
|
|
|
@@ -277,7 +284,7 @@ class Wechat extends Api
|
|
|
* @return array
|
|
|
* @throws AuthorizeFailedException
|
|
|
*/
|
|
|
- public function OfficialAccountSigning(string $appid,string $mch_id, string $plan_id, string $contract_code, string $request_serial, string $contract_display_account, string $notify_url, string $version, string $sign,string $timestamp): array
|
|
|
+ public function OfficialAccountSigning(string $appid, string $mch_id, string $plan_id, string $contract_code, string $request_serial, string $contract_display_account, string $notify_url, string $version, string $sign, string $timestamp): array
|
|
|
{
|
|
|
|
|
|
$url = 'https://api.mch.weixin.qq.com/papay/entrustweb';
|
|
@@ -297,11 +304,15 @@ class Wechat extends Api
|
|
|
$response = $this->curl_get($url, $info);
|
|
|
return $response;
|
|
|
}
|
|
|
- public function test() {
|
|
|
+
|
|
|
+ public function test()
|
|
|
+ {
|
|
|
return '123456';
|
|
|
}
|
|
|
- public function signing_plan() {
|
|
|
- $this->success('获取成功',WechatPlan::where('cid',$this->cid)->select());
|
|
|
+
|
|
|
+ public function signing_plan()
|
|
|
+ {
|
|
|
+ return $this->success('获取成功', WechatPlan::where('cid', $this->cid)->select());
|
|
|
}
|
|
|
|
|
|
}
|