WxV3.php 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593
  1. <?php
  2. /**
  3. * 重庆赤晓店信息科技有限公司
  4. * https://www.chixiaodian.com
  5. * Copyright (c) 2023 赤店商城 All rights reserved.
  6. */
  7. namespace app\utils\WechatMerchant;
  8. use app\models\Cash;
  9. use app\models\MerchantInfo;
  10. use app\models\Option;
  11. use EasyWeChat\Factory;
  12. use yii\base\Exception;
  13. use yii\helpers\Json;
  14. use app\models\Store;
  15. class WxV3 {
  16. public $wechat;
  17. // 服务商小程序appid
  18. private $service_app_id;
  19. // 商户mchid
  20. private $mch_id;
  21. // 商户API v3密钥(微信服务商-账户中心-API安全 api v3密钥 https://pay.weixin.qq.com/index.php/core/cert/api_cert)
  22. private $mch_api_key;
  23. // 证书编号 (apiclient_cert.pem证书解析后获得)
  24. private $serial_no;
  25. // 私钥 apiclient_key.pem(微信服务商-账户中心-API安全 自行下载 https://pay.weixin.qq.com/index.php/core/cert/api_cert)
  26. private $mch_private_key;
  27. // 支付平台公钥(接口获取)
  28. private $public_key_path;
  29. private $pay_public_key;
  30. private $pay_public_key_id;
  31. /**
  32. * @var string 获取平台证书接口
  33. */
  34. private $certificates_url = 'https://api.mch.weixin.qq.com/v3/certificates';
  35. public function __construct($wechat = null) {
  36. $wechat && $this->setWechat($wechat);
  37. }
  38. public function setWechat($wechat) {
  39. $this->wechat = $wechat;
  40. $data = $this->wechat->getConfig();
  41. $this->service_app_id = $data['app_id'];
  42. $this->mch_private_key = $data['key_path'];
  43. $this->public_key_path = $data['cert_path'];
  44. $this->mch_id = $data['mch_id'];
  45. $this->mch_api_key = $data['key'];
  46. // $this->serial_no = $this->parseSerialNo($this->getCertFicates());
  47. \Yii::error([$this->mch_id, $this->mch_api_key, $this->serial_no, $this->service_app_id]);
  48. }
  49. /**
  50. * 获取微信支付平台证书
  51. */
  52. public function certFicates() {
  53. $url = $this->certificates_url;
  54. // 获取认证信息
  55. $authorization = $this->getAuthorization($url);
  56. $header = [
  57. 'Content-Type:application/json',
  58. 'Accept:application/json',
  59. 'User-Agent:' . $this->mch_id,
  60. 'Authorization:' . $authorization
  61. ];
  62. $json = $this->getCurl('GET', $url, '', $header);
  63. $data = json_decode($json, true);
  64. if (isset($data['code']) && isset($data['message'])) {
  65. return [
  66. 'code' => 1,
  67. 'msg' => $data['message']
  68. ];
  69. }
  70. if (empty($cfdata = $data['data'][0])) {
  71. return [
  72. 'code' => 1,
  73. 'msg' => '返回错误'
  74. ];
  75. }
  76. return $cfdata;
  77. }
  78. /**
  79. * 获取认证信息
  80. * @param string $url
  81. * @param string $http_method
  82. * @param string $body
  83. * @return string
  84. * @throws Exception
  85. */
  86. private function getAuthorization($url, $http_method = 'GET', $body = '') {
  87. if (!in_array('sha256WithRSAEncryption', \openssl_get_md_methods(true))) {
  88. throw new \Exception("当前PHP环境不支持SHA256withRSA");
  89. }
  90. //私钥地址
  91. $mch_private_key = $this->mch_private_key;
  92. //商户号
  93. $merchant_id = $this->mch_id;
  94. //当前时间戳
  95. $timestamp = time();
  96. //随机字符串
  97. $nonce = $this->getNonceStr();
  98. //证书编号
  99. $serial_no = $this->serial_no;
  100. $url_parts = parse_url($url);
  101. $canonical_url = ($url_parts['path'] . (!empty($url_parts['query']) ? "?${url_parts['query']}" : ""));
  102. $message = $http_method . "\n" .
  103. $canonical_url . "\n" .
  104. $timestamp . "\n" .
  105. $nonce . "\n" .
  106. $body . "\n";
  107. openssl_sign($message, $raw_sign, \openssl_get_privatekey(\file_get_contents($mch_private_key)), 'sha256WithRSAEncryption');
  108. $sign = base64_encode($raw_sign);
  109. $schema = 'WECHATPAY2-SHA256-RSA2048';
  110. $token = sprintf('mchid="%s",nonce_str="%s",timestamp="%d",serial_no="%s",signature="%s"',
  111. $merchant_id, $nonce, $timestamp, $serial_no, $sign);
  112. return $schema . ' ' . $token;
  113. }
  114. /**
  115. * 敏感字符加密
  116. * @param $str
  117. * @return string
  118. * @throws Exception
  119. */
  120. private function getEncrypt($str) {
  121. static $content;
  122. if (empty($content)) {
  123. $content = $this->getCertFicates();
  124. }
  125. // 去除内容中的空格
  126. $str = preg_replace("/\s| /", '', $str);
  127. $encrypted = '';
  128. if (openssl_public_encrypt($str, $encrypted, $content, OPENSSL_PKCS1_OAEP_PADDING)) {
  129. //base64编码
  130. $sign = base64_encode($encrypted);
  131. } else {
  132. throw new \Exception('encrypt failed');
  133. }
  134. return $sign;
  135. }
  136. /**
  137. * 获取支付平台证书
  138. * @return false|string
  139. */
  140. private function getCertFicates() {
  141. if($this->pay_public_key){
  142. return $this->pay_public_key;
  143. }
  144. if(!$this->public_key_path){
  145. $Merchant = new Merchant();
  146. return $Merchant->getCertFicates();
  147. }
  148. $public_key_path = $this->public_key_path;
  149. if (!file_exists($public_key_path)) {
  150. \Yii::error([__METHOD__]);
  151. $cfData = $this->certFicates();
  152. $content = $this->decryptToString($cfData['encrypt_certificate']['associated_data'], $cfData['encrypt_certificate']['nonce'], $cfData['encrypt_certificate']['ciphertext'], $this->mch_api_key);
  153. file_put_contents($public_key_path, $content);
  154. } else {
  155. $content = file_get_contents($public_key_path);
  156. }
  157. return $content;
  158. }
  159. /**
  160. * 业务编号
  161. * @return string
  162. */
  163. public function getBusinessCode() {
  164. return date('Ymd') . substr(time(), -5) . substr(microtime(), 2, 5) . sprintf('%02d', rand(0, 99));
  165. }
  166. /**
  167. * 随机字符串
  168. * @param int $length
  169. * @return string
  170. */
  171. private function getNonceStr($length = 16) {
  172. // 密码字符集,可任意添加你需要的字符
  173. $chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
  174. $str = "";
  175. for ($i = 0; $i < $length; $i++) {
  176. $str .= $chars[mt_rand(0, strlen($chars) - 1)];
  177. }
  178. return $str;
  179. }
  180. /**
  181. * @param string $method
  182. * @param string $url
  183. * @param array|string $data
  184. * @param array $headers
  185. * @param int $timeout
  186. * @return bool|string
  187. */
  188. private function getCurl($method = 'GET', $url, $data, $headers = [], $timeout = 30) {
  189. $curl = curl_init();
  190. curl_setopt($curl, CURLOPT_URL, $url);
  191. curl_setopt($curl, CURLOPT_HEADER, false);
  192. curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
  193. curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
  194. curl_setopt($curl, CURLOPT_SSLVERSION, false);
  195. curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
  196. curl_setopt($curl, CURLOPT_TIMEOUT, $timeout);
  197. if (!empty($headers)) {
  198. curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
  199. }
  200. if ($method == 'POST') {
  201. curl_setopt($curl, CURLOPT_POST, TRUE);
  202. curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
  203. }
  204. $result = curl_exec($curl);
  205. curl_close($curl);
  206. return $result;
  207. }
  208. /**
  209. * Decrypt AEAD_AES_256_GCM ciphertext(官方案例-已改造)
  210. *
  211. * @param string $associatedData AES GCM additional authentication data
  212. * @param string $nonceStr AES GCM nonce
  213. * @param string $ciphertext AES GCM cipher text
  214. *
  215. * @return string|bool Decrypted string on success or FALSE on failure
  216. */
  217. public function decryptToString($associatedData, $nonceStr, $ciphertext, $aesKey) {
  218. $auth_tag_length_byte = 16;
  219. $ciphertext = \base64_decode($ciphertext);
  220. if (strlen($ciphertext) <= $auth_tag_length_byte) {
  221. return false;
  222. }
  223. // ext-sodium (default installed on >= PHP 7.2)
  224. if (function_exists('\sodium_crypto_aead_aes256gcm_is_available') &&
  225. \sodium_crypto_aead_aes256gcm_is_available()) {
  226. return \sodium_crypto_aead_aes256gcm_decrypt($ciphertext, $associatedData, $nonceStr, $aesKey);
  227. }
  228. // ext-libsodium (need install libsodium-php 1.x via pecl)
  229. if (function_exists('\Sodium\crypto_aead_aes256gcm_is_available') &&
  230. \Sodium\crypto_aead_aes256gcm_is_available()) {
  231. return \Sodium\crypto_aead_aes256gcm_decrypt($ciphertext, $associatedData, $nonceStr, $aesKey);
  232. }
  233. // openssl (PHP >= 7.1 support AEAD)
  234. if (PHP_VERSION_ID >= 70100 && in_array('aes-256-gcm', \openssl_get_cipher_methods())) {
  235. $ctext = substr($ciphertext, 0, -$auth_tag_length_byte);
  236. $authTag = substr($ciphertext, -$auth_tag_length_byte);
  237. return \openssl_decrypt($ctext, 'aes-256-gcm', $aesKey, \OPENSSL_RAW_DATA, $nonceStr,
  238. $authTag, $associatedData);
  239. }
  240. throw new \Exception('AEAD_AES_256_GCM需要PHP 7.1以上或者安装libsodium-php');
  241. }
  242. /**
  243. * 获取证书编号(官方案例-已改造)
  244. * @param $certificate
  245. * @return string
  246. */
  247. private function parseSerialNo($certificate) {
  248. $info = \openssl_x509_parse($certificate);
  249. if (!isset($info['serialNumber']) && !isset($info['serialNumberHex'])) {
  250. throw new \InvalidArgumentException('证书格式错误');
  251. }
  252. $serialNo = '';
  253. // PHP 7.0+ provides serialNumberHex field
  254. if (isset($info['serialNumberHex'])) {
  255. $serialNo = $info['serialNumberHex'];
  256. } else {
  257. // PHP use i2s_ASN1_INTEGER in openssl to convert serial number to string,
  258. // i2s_ASN1_INTEGER may produce decimal or hexadecimal format,
  259. // depending on the version of openssl and length of data.
  260. if (\strtolower(\substr($info['serialNumber'], 0, 2)) == '0x') { // HEX format
  261. $serialNo = \substr($info['serialNumber'], 2);
  262. } else { // DEC format
  263. $value = $info['serialNumber'];
  264. $hexvalues = ['0', '1', '2', '3', '4', '5', '6', '7',
  265. '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'];
  266. while ($value != '0') {
  267. $serialNo = $hexvalues[\bcmod($value, '16')] . $serialNo;
  268. $value = \bcdiv($value, '16', 0);
  269. }
  270. }
  271. }
  272. return \strtoupper($serialNo);
  273. }
  274. //商家转账
  275. public function transferBatches($store_id, $data) {
  276. $url = 'https://api.mch.weixin.qq.com/v3/transfer/batches';
  277. $_data = [
  278. 'appid' => $this->service_app_id,
  279. 'out_batch_no' => $data['partner_trade_no'],
  280. 'batch_name' => $data['partner_trade_no'],
  281. 'batch_remark' => $data['desc'],
  282. 'total_amount' => (int)$data['amount'],
  283. 'total_num' => 1,
  284. 'transfer_detail_list' => [[
  285. 'out_detail_no' => $data['partner_trade_no'],
  286. 'transfer_amount' => (int)$data['amount'],
  287. 'transfer_remark' => $data['desc'],
  288. 'openid' => $data['openid'],
  289. ]],
  290. 'notify_url' => 'https://' . \Yii::$app->request->hostName . '/index.php/wechat/transfer-batches-notify',
  291. ];
  292. $serial_no = $this->serial_no;
  293. $store = Store::findOne($store_id);
  294. $wechat_cash = Option::get('wechat_cash', $store_id, 'store')['value'];
  295. if($store->is_platform_transfers == 1){
  296. $wechat_cash = Option::get('store_wechat_cash', $store_id, 'store')['value'];
  297. }
  298. if ($wechat_cash) {
  299. $wechat_cash = json_decode($wechat_cash, true);
  300. }
  301. if ($wechat_cash && $wechat_cash['appid']) {
  302. $this->serial_no = $wechat_cash['serial_no'];
  303. $this->pay_public_key = $wechat_cash['pay_public_key'];
  304. $this->pay_public_key_id = $wechat_cash['pay_public_key_id'];
  305. if (intval($wechat_cash['is_open']) === 2) {
  306. $url = 'https://api.mch.weixin.qq.com/v3/fund-app/mch-transfer/transfer-bills';
  307. $_data = [
  308. 'appid' => $wechat_cash['appid'],
  309. 'out_bill_no' => $data['partner_trade_no'],
  310. 'transfer_scene_id' => '1000',//转账场景ID
  311. 'openid' => $data['openid'],
  312. 'user_name' => $this->getEncrypt($data['user_name']),//收款方真实姓名
  313. 'transfer_amount' => (int)$data['amount'],
  314. 'transfer_remark' => $data['desc'],
  315. 'notify_url' => pay_notify_url('wechat/transfer-batches-notify', $store_id),
  316. // 'user_recv_perception' => '劳务报酬',
  317. 'transfer_scene_report_infos' => [
  318. [
  319. "info_type" =>"活动名称",
  320. "info_content" => "账户提现"
  321. ],
  322. [
  323. "info_type" =>"奖励说明",
  324. "info_content" => "账户金额提现"
  325. ]
  326. ]
  327. ];
  328. if ((int)$data['amount'] < 200000) {
  329. $_data['user_name'] = '';
  330. }
  331. } else {
  332. $_data['appid'] = $wechat_cash['appid'];
  333. }
  334. if($this->pay_public_key){
  335. $serial_no = $this->pay_public_key_id;
  336. }else{
  337. $serial_no = $this->serial_no;
  338. }
  339. $bodyData = json_encode($_data,JSON_UNESCAPED_UNICODE);
  340. debug_log(['data' => $bodyData], 'wechatTransferBatchesNotify.log');
  341. $authorization = $this->getWechatAuthorization($url, 'POST', $bodyData, $store_id);
  342. // $wechat_cash = json_decode($wechat_cash, true);
  343. // $_data['appid'] = $wechat_cash['appid'];
  344. // $_data['mch_id'] = $wechat_cash['mch_id'];
  345. //
  346. // $config = $_data;
  347. //// $cert_pem_file = null;
  348. //// if ($this->wechat_config->cert_pem) {
  349. //// $cert_pem_file = \Yii::$app->runtimePath . '/pem/' . md5($this->wechat_config->cert_pem);
  350. //// if (!file_exists($cert_pem_file)) {
  351. //// file_put_contents($cert_pem_file, $this->wechat_config->cert_pem);
  352. //// }
  353. //// }
  354. //
  355. // $wechat = Factory::payment($config);
  356. } else {
  357. $bodyData = json_encode($_data);
  358. // 获取认证信息
  359. $hasIncoming = \app\models\Store::hasIncoming($store_id);
  360. if($hasIncoming){
  361. return $this->res([
  362. 'code' => 1,
  363. 'msg' => '店铺内未配置提现参数',
  364. ]);
  365. // $Merchant = new Merchant();
  366. // $authorization = $Merchant->getAuthorization($url, 'POST', $bodyData);
  367. }else{
  368. $this->serial_no = Option::get('platform_mch_api_serial_no', 0, 'saas')['value'];
  369. $this->pay_public_key = Option::get('platform_mch_public_key', 0, 'saas')['value'];
  370. $this->pay_public_key_id = Option::get('platform_mch_public_key_id', 0, 'saas')['value'];
  371. if($this->pay_public_key){
  372. $serial_no = $this->pay_public_key_id;
  373. }else{
  374. $serial_no = $this->serial_no;
  375. }
  376. //商城提现
  377. $url = 'https://api.mch.weixin.qq.com/v3/fund-app/mch-transfer/transfer-bills';
  378. $_data = [
  379. 'appid' => $this->service_app_id,
  380. 'out_bill_no' => $data['partner_trade_no'],
  381. 'transfer_scene_id' => '1000',//转账场景ID
  382. 'openid' => $data['openid'],
  383. 'user_name' => '',//收款方真实姓名 $this->getEncrypt($data['user_name'])这块先给空 因为前端没有设置真实姓名的地方
  384. 'transfer_amount' => (int)$data['amount'],
  385. 'transfer_remark' => $data['desc'],
  386. 'notify_url' => pay_notify_url('wechat/transfer-batches-notify', $store_id, 1),
  387. // 'user_recv_perception' => '劳务报酬',
  388. 'transfer_scene_report_infos' => [
  389. [
  390. "info_type" =>"活动名称",
  391. "info_content" => "账户提现"
  392. ],
  393. [
  394. "info_type" =>"奖励说明",
  395. "info_content" => "账户金额提现"
  396. ]
  397. ]
  398. ];
  399. if ((int)$data['amount'] < 200000) {
  400. $_data['user_name'] = '';
  401. }
  402. $bodyData = json_encode($_data,JSON_UNESCAPED_UNICODE);
  403. $authorization = $this->getAuthorization($url, 'POST', $bodyData);
  404. }
  405. }
  406. $header = [
  407. 'Content-Type:application/json',
  408. 'Accept:application/json',
  409. 'User-Agent:*/*',
  410. 'Authorization:' . $authorization,
  411. 'Wechatpay-Serial:' . $serial_no
  412. ];
  413. $json = $this->getCurl('POST', $url, $bodyData, $header);
  414. \Yii::error([__METHOD__, $store_id, $_data, $header, $json]);
  415. $res = json_decode($json, true);
  416. debug_log([$store_id, $_data, $header, $res], 'wechatTransferBatchesNotify.log');
  417. if (isset($res['code']) && isset($res['message'])) {
  418. return $this->res([
  419. 'code' => 1,
  420. 'msg' => $res['code'] . $res['message']
  421. ]);
  422. }
  423. if (!($wechat_cash && intval($wechat_cash['is_open']) === 2)) {
  424. if (empty($res['batch_id'])) {
  425. // return $this->res([
  426. // 'code' => 1,
  427. // 'msg' => '返回错误'
  428. // ]);
  429. }
  430. }
  431. return $this->res(['code' => 0, 'data' => $res]);
  432. }
  433. /**
  434. * 获取认证信息
  435. * @param string $url
  436. * @param string $http_method
  437. * @param string $body
  438. * @return string
  439. * @throws Exception
  440. */
  441. private function getWechatAuthorization($url, $http_method = 'GET', $body = '', $store_id = 0) {
  442. if (!in_array('sha256WithRSAEncryption', \openssl_get_md_methods(true))) {
  443. throw new \Exception("当前PHP环境不支持SHA256withRSA");
  444. }
  445. $store = Store::findOne($store_id);
  446. $wechat_cash = Option::get('wechat_cash', $store_id, 'store')['value'];
  447. if($store->is_platform_transfers == 1){
  448. $wechat_cash = Option::get('store_wechat_cash', $store_id, 'store')['value'];
  449. }
  450. if ($wechat_cash) {
  451. $wechat_cash = json_decode($wechat_cash, true);
  452. $mch_private_key = $wechat_cash['mch_private_key'];
  453. $merchant_id = $wechat_cash['mch_id'];
  454. $serial_no = $wechat_cash['serial_no'];
  455. $timestamp = time();
  456. $nonce = $this->getNonceStr();
  457. $url_parts = parse_url($url);
  458. $canonical_url = ($url_parts['path'] . (!empty($url_parts['query']) ? "?${url_parts['query']}" : ""));
  459. $message = $http_method . "\n" .
  460. $canonical_url . "\n" .
  461. $timestamp . "\n" .
  462. $nonce . "\n" .
  463. $body . "\n";
  464. openssl_sign($message, $raw_sign, \openssl_get_privatekey($mch_private_key), 'sha256WithRSAEncryption');
  465. $sign = base64_encode($raw_sign);
  466. $schema = 'WECHATPAY2-SHA256-RSA2048';
  467. $token = sprintf('mchid="%s",nonce_str="%s",timestamp="%d",serial_no="%s",signature="%s"',
  468. $merchant_id, $nonce, $timestamp, $serial_no, $sign);
  469. return $schema . ' ' . $token;
  470. }
  471. }
  472. public function res($res){
  473. if($res['code'] == 0){
  474. $res['result_code'] = 'SUCCESS';
  475. }else{
  476. $res['err_code_des'] = $res['msg'];
  477. }
  478. return $res;
  479. }
  480. public function getBatchDetail($store_id, $data) {
  481. $out_batch_no = $data['out_batch_no'];
  482. $url = "https://api.mch.weixin.qq.com/v3/transfer/batches/out-batch-no/". $out_batch_no . "/details/out-detail-no/". $out_batch_no;
  483. $serial_no = $this->serial_no;
  484. $wechat_cash = Option::get('wechat_cash', $store_id, 'store')['value'];
  485. if ($wechat_cash) {
  486. $wechat_cash = json_decode($wechat_cash, true);
  487. $serial_no = $wechat_cash['serial_no'];
  488. $bodyData = '';
  489. $authorization = $this->getWechatAuthorization($url, 'GET', $bodyData, $store_id);
  490. // $wechat_cash = json_decode($wechat_cash, true);
  491. // $_data['appid'] = $wechat_cash['appid'];
  492. // $_data['mch_id'] = $wechat_cash['mch_id'];
  493. //
  494. // $config = $_data;
  495. //// $cert_pem_file = null;
  496. //// if ($this->wechat_config->cert_pem) {
  497. //// $cert_pem_file = \Yii::$app->runtimePath . '/pem/' . md5($this->wechat_config->cert_pem);
  498. //// if (!file_exists($cert_pem_file)) {
  499. //// file_put_contents($cert_pem_file, $this->wechat_config->cert_pem);
  500. //// }
  501. //// }
  502. //
  503. // $wechat = Factory::payment($config);
  504. } else {
  505. $bodyData = '';
  506. // 获取认证信息
  507. $hasIncoming = \app\models\Store::hasIncoming($store_id);
  508. if($hasIncoming){
  509. $Merchant = new Merchant();
  510. $authorization = $Merchant->getAuthorization($url, 'GET', $bodyData);
  511. }else{
  512. $authorization = $this->getAuthorization($url, 'GET', $bodyData);
  513. }
  514. }
  515. $header = [
  516. 'Content-Type:application/json',
  517. 'Accept:application/json',
  518. 'User-Agent:*/*',
  519. 'Authorization:' . $authorization,
  520. 'Wechatpay-Serial:' . $serial_no
  521. ];
  522. $json = $this->getCurl('GET', $url, $bodyData, $header);
  523. $res = json_decode($json, true);
  524. if (isset($res['code']) && isset($res['message'])) {
  525. return $this->res([
  526. 'code' => 1,
  527. 'msg' => $res['code'] . $res['message']
  528. ]);
  529. }
  530. // if ($res['detail_status'] === "WAIT_PAY") {
  531. // $res['fail_reason_text'] = "待确认";
  532. // }
  533. // if ($res['detail_status'] === "PROCESSING") {
  534. // $res['fail_reason_text'] = "转账中";
  535. // }
  536. // if ($res['detail_status'] === "SUCCESS") {
  537. // $res['fail_reason_text'] = "转账成功";
  538. // }
  539. // if ($res['detail_status'] === "FAIL") {
  540. // $res['fail_reason_text'] = "转账失败:" . Cash::WX_CASH_FAIL_REASON[$res['fail_reason']];
  541. // }
  542. return $this->res(['code' => 0, 'msg' => $res['fail_reason_text'], 'data' => $res]);
  543. }
  544. }