|
@@ -101,280 +101,280 @@ class Wechat extends Api
|
|
|
@file_put_contents("error.txt", $e->getFile() . '-', $e->getLine(), '-' . $e->getMessage());
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
- * 扣款服务
|
|
|
- * @param Request $request
|
|
|
- * @return mixed
|
|
|
- * @throws \think\db\exception\DataNotFoundException
|
|
|
- * @throws \think\db\exception\ModelNotFoundException
|
|
|
- * @throws \think\exception\DbException
|
|
|
- */
|
|
|
- public function signing(Request $request)
|
|
|
- {
|
|
|
- $price = intval($request->param('price'));
|
|
|
- $uid = intval($request->param('uid'));
|
|
|
- $cid = intval($request->param('cid'));
|
|
|
- $plan_id = WechatPlan::where('price', $price)->value('plan_id');
|
|
|
- $p_id = WechatPlan::where('price', $price)->value('id');
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- try {
|
|
|
-
|
|
|
-
|
|
|
- $app_id = Company::where('id', $cid)->value('wechat_appid');
|
|
|
-
|
|
|
- $mch_id = Company::where('id', $cid)->value('pay_weixin_mchid');
|
|
|
- $key = Company::where('id', $cid)->value('pay_weixin_key');
|
|
|
- @file_put_contents("quanju.txt", $key . "-key\r\n", 8);
|
|
|
- $contract_code = $this->generateRandomString(12);
|
|
|
- $notify_url = Request::instance()->domain() . "/api/wechat/notify/" . $cid;
|
|
|
-
|
|
|
-
|
|
|
- $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 = User::where('id', $uid)->value('nickname');
|
|
|
- if (empty($contract_display_account)){
|
|
|
- $this->error('用户不存在!');
|
|
|
- }
|
|
|
- $timestamp = time();
|
|
|
- $version = '1.0';
|
|
|
- $array = array(
|
|
|
- 'appid' => $app_id,
|
|
|
- 'mch_id' => $mch_id,
|
|
|
- 'plan_id' => $plan_id,
|
|
|
-
|
|
|
- '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", $xml . "-签约内容\r\n", 8);
|
|
|
- $sign = $this->md5_sign($xml, $key);
|
|
|
- @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);
|
|
|
-
|
|
|
- $response = $this->curl_get($url);
|
|
|
-
|
|
|
- @file_put_contents("quanju.txt", $response . "-返回链接\r\n", 8);
|
|
|
-
|
|
|
- WechatPlanRecord::create([
|
|
|
- 'uid' => $uid,
|
|
|
- 'plan_id' => $plan_id,
|
|
|
- 'price' => $price,
|
|
|
- 'is_signing' => 0,
|
|
|
- 'request_serial' => $request_serial,
|
|
|
- 'contract_code' => $contract_code,
|
|
|
- 'contract_display_account' => $contract_display_account,
|
|
|
- 'createtime' => time(),
|
|
|
- 'cid' => 12,
|
|
|
- ]);
|
|
|
-
|
|
|
- $this->success('获取成功', $response);
|
|
|
-
|
|
|
- } catch (Exception $e) {
|
|
|
-
|
|
|
- @file_put_contents("quanju.txt", $e->getMessage() . "-报错信息\r\n", 8);
|
|
|
- @file_put_contents("error.txt", $e->getFile() . '-', $e->getLine(), '-' . $e->getMessage());
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- * 解约扣款服务
|
|
|
- * @param Request $request
|
|
|
- * @return mixed
|
|
|
- * @throws \think\db\exception\DataNotFoundException
|
|
|
- * @throws \think\db\exception\ModelNotFoundException
|
|
|
- * @throws \think\exception\DbException
|
|
|
- */
|
|
|
- public function delete_signing(Request $request)
|
|
|
- {
|
|
|
- $record_id = intval($request->param('id'));
|
|
|
- $uid = intval($request->param('uid'));
|
|
|
- $cid = intval($request->param('uid'));
|
|
|
- try {
|
|
|
-
|
|
|
- $app_id = Company::where('id', $cid)->value('wechat_appid');
|
|
|
- $mch_id = Company::where('id', $cid)->value('pay_weixin_mchid');
|
|
|
- $contract_code = WechatPlanRecord::where('id', $record_id)->value('contract_code');
|
|
|
- $plan_id = WechatPlanRecord::where('id', $record_id)->value('plan_id');
|
|
|
- $contract_termination_remark = '解约备注';
|
|
|
- $version = '1.0';
|
|
|
- $array = array(
|
|
|
- 'appid' => $app_id,
|
|
|
- 'mch_id' => $mch_id,
|
|
|
- 'plan_id' => $plan_id,
|
|
|
- 'contract_code' => $contract_code,
|
|
|
- 'contract_termination_remark' => $contract_termination_remark,
|
|
|
- '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/deletecontract?' . $xml . '&sign=' . $sign;
|
|
|
- @file_put_contents("quanju.txt", $url . "-链接\r\n", 8);
|
|
|
- var_dump($url);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- WechatPlanRecord::where('id', $record_id)->update(['is_signing' => 1]);
|
|
|
- die();
|
|
|
- return 1;
|
|
|
- } catch (Exception $e) {
|
|
|
- @file_put_contents("error.txt", $e->getFile() . '-', $e->getLine(), '-' . $e->getMessage());
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- public function generateRandomString($length)
|
|
|
- {
|
|
|
- $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
|
|
|
- $charactersLength = strlen($characters);
|
|
|
- $randomString = '';
|
|
|
- for ($i = 0; $i < $length; $i++) {
|
|
|
- $randomString .= $characters[rand(0, $charactersLength - 1)];
|
|
|
- }
|
|
|
- return $randomString;
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- public function generateUniqueSerialNumber()
|
|
|
- {
|
|
|
-
|
|
|
- $uniqueId = ltrim(uniqid('', true), '0');
|
|
|
-
|
|
|
-
|
|
|
- while (strlen($uniqueId) > 19 || substr($uniqueId, 0, 1) === '0') {
|
|
|
- $uniqueId = ltrim(uniqid('', true), '0');
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- $serialNumber = preg_replace('/\D/', '', $uniqueId);
|
|
|
-
|
|
|
-
|
|
|
- if (substr($serialNumber, 0, 1) === '0') {
|
|
|
- $serialNumber = generateUniqueSerialNumber();
|
|
|
- }
|
|
|
-
|
|
|
- return $serialNumber;
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- public function curl_post($url = '', $name = array(), $timeout = 100)
|
|
|
- {
|
|
|
-
|
|
|
- $ch = curl_init();
|
|
|
- curl_setopt($ch, CURLOPT_URL, $url);
|
|
|
- curl_setopt($ch, CURLOPT_HEADER, false);
|
|
|
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
|
|
- curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
|
|
|
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
|
|
|
- curl_setopt($ch, CURLOPT_POST, true);
|
|
|
-
|
|
|
- $post_data = json_encode($name);
|
|
|
-
|
|
|
- curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
|
|
|
- $content = curl_exec($ch);
|
|
|
-
|
|
|
- curl_close($ch);
|
|
|
- $content = json_decode($content, true);
|
|
|
- return $content;
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- public function curl_get(string $url, $timeout = 100)
|
|
|
- {
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
|
|
|
-
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
|
|
|
-
|
|
|
- $ch = curl_init();
|
|
|
- curl_setopt($ch, CURLOPT_URL, $url);
|
|
|
- curl_setopt($ch, CURLOPT_HEADER, false);
|
|
|
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
|
|
- curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
|
|
|
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
|
|
|
-
|
|
|
- $content = curl_exec($ch);
|
|
|
- curl_close($ch);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
|
|
|
-
|
|
|
- var_dump($content);die();
|
|
|
- return $content;
|
|
|
- }
|
|
|
-
|
|
|
- public function md5_sign($data, $key)
|
|
|
- {
|
|
|
- $stringSignTemp = $data . "&key=$key";
|
|
|
-
|
|
|
- $sign = MD5($stringSignTemp);
|
|
|
- $sign = strtoupper($sign);
|
|
|
- return $sign;
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- * 公众号签约
|
|
|
- * see:https:
|
|
|
- * @param array $data
|
|
|
- *
|
|
|
- * @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
|
|
|
- {
|
|
|
-
|
|
|
- $url = 'https://api.mch.weixin.qq.com/papay/entrustweb';
|
|
|
- $info = [
|
|
|
- 'appid' => $appid,
|
|
|
- 'mch_id' => $mch_id,
|
|
|
- 'plan_id' => $plan_id,
|
|
|
-
|
|
|
- 'contract_code' => $contract_code,
|
|
|
- 'request_serial' => $request_serial,
|
|
|
- 'contract_display_account' => $contract_display_account,
|
|
|
- 'notify_url' => $notify_url,
|
|
|
- 'version' => $version,
|
|
|
- 'sign' => $sign,
|
|
|
- 'timestamp' => $timestamp
|
|
|
- ];
|
|
|
- $response = $this->curl_get($url, $info);
|
|
|
- return $response;
|
|
|
- }
|
|
|
-
|
|
|
- public function test()
|
|
|
- {
|
|
|
- return '123456';
|
|
|
- }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
|
|
|
public function signing_plan()
|
|
|
{
|