Yspay.php 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669
  1. <?php namespace Pay\Lib;
  2. use Dever;
  3. #银联商务正常交易
  4. class Yspay extends Core
  5. {
  6. public function __construct($config)
  7. {
  8. $project = Dever::project('pay');
  9. # 通知接口
  10. $config['notify'] = $this->url($config['type'], $config['id']);
  11. $set = explode('|', $config['mchid']);
  12. $config['mid'] = $set[0];
  13. $config['tid'] = $set[1];
  14. if (isset($set[2])) {
  15. $config['prefix'] = $set[2];
  16. }
  17. $set = explode('|', $config['key']);
  18. $config['sub_appid'] = $set[0];
  19. $config['sub_appsecret'] = $set[1];
  20. if (isset($set[2])) {
  21. $config['key'] = $set[2];
  22. }
  23. $this->config = $config;
  24. }
  25. /**
  26. * 通知
  27. */
  28. public function notify()
  29. {
  30. $input = file_get_contents("php://input");
  31. if ($input) {
  32. parse_str($input, $input);
  33. } else {
  34. $input = Dever::input();
  35. }
  36. $test = Dever::input('test');
  37. if ($test == 1) {
  38. $input = json_decode('{"msgType":"wx.notify","payTime":"2021-12-29 18:24:42","buyerCashPayAmt":"1","connectSys":"UNIONPAY","sign":"E82978003E0121B320D3520B1930FB4C2072B639126F3427351631F1D0A998CF","merName":"中食民安(北京)科技有限公司","mid":"89810007372106N","invoiceAmount":"1","settleDate":"2021-12-29","billFunds":"现金:1","buyerId":"otdJ_uD-zTNmDn7-u13oActXu8lA","mchntUuid":"2d9081bd7db8ad75017dbbe68981314f","tid":"DM098308","instMid":"MINIDEFAULT","receiptAmount":"1","couponAmount":"0","targetOrderId":"4200001344202112290882463274","signType":"SHA256","billFundsDesc":"现金支付0.01元。","subBuyerId":"oGlMn5e_vdYK8uAaCgyexarFKBrY","orderDesc":"中食民安(北京)科技有限公司","seqId":"25267273719N","merOrderId":"138K_G202112297347788956443487","targetSys":"WXPay","bankInfo":"OTHERS","totalAmount":"1","createTime":"2021-12-29 18:24:38","buyerPayAmount":"1","iB":"KRHn","notifyId":"d4122965-b772-4f8f-b5c4-f3d483da0962","subInst":"100000","status":"TRADE_SUCCESS"}', true);
  39. $input = json_decode('{"bankInfo":"OTHERS","billDate":"2022-01-06","billDesc":"中食民安(北京)科技有限公司","billNo":"138KG202201064666839470673943","billPayment":"{\"payTime\":\"2022-01-06 13:24:56\",\"buyerCashPayAmt\":1,\"paySeqId\":\"25394941600N\",\"invoiceAmount\":1,\"settleDate\":\"2022-01-06\",\"buyerId\":\"otdJ_uHh75dIaI6EKu-6usw0hjD4\",\"receiptAmount\":1,\"totalAmount\":1,\"couponAmount\":0,\"billBizType\":\"bills\",\"buyerPayAmount\":1,\"targetOrderId\":\"4200001348202201065614123115\",\"payDetail\":\"现金支付0.01元。\",\"merOrderId\":\"138KG2022010646668394706739430\",\"status\":\"TRADE_SUCCESS\",\"targetSys\":\"WXPay\"}","billQRCode":"https:\/\/qr.95516.com\/48020000\/138K2201066502428138291294","billStatus":"PAID","createTime":"2022-01-06 13:24:28","instMid":"QRPAYDEFAULT","mchntUuid":"2d9081bd7db8ad75017dbbe68981314f","merName":"中食民安(北京)科技有限公司","mid":"89810007372106N","notifyId":"49a83755-b476-47c3-a0b6-629dc7a43742","qrCodeId":"138K2201066502428138291294","qrCodeType":"BILLPAY","receiptAmount":"1","seqId":"25394941600N","signType":"SHA256","subInst":"100000","tid":"DM098308","totalAmount":"1","vE":"Bclv","sign":"1D048E292E17225A4EEF4AB438630601A19E50CDA71DF9E7A4304AABBD134A38","e_sign":"1D048E292E17225A4EEF4AB438630601A19E50CDA71DF9E7A4304AABBD134A38"}', true);
  40. }
  41. $sign = $input['sign'];
  42. unset($input['sign']);
  43. if (isset($input['e_sign'])) {
  44. unset($input['e_sign']);
  45. }
  46. ksort($input);
  47. $string = array();
  48. foreach ($input as $k => $v) {
  49. if (strstr($v, '&') || strstr($v, '@')) {
  50. $v = urlencode($v);
  51. }
  52. $string[] = $k . '=' . $v;
  53. }
  54. $string = implode('&', $string);
  55. $string .= $this->config['key'];
  56. if ($input['signType'] == 'SHA256') {
  57. $string = hash("sha256", $string);
  58. } else {
  59. $string = md5($string);
  60. }
  61. $string = strtoupper($string);
  62. $input['sign'] = $sign;
  63. $input['e_sign'] = $string;
  64. $this->log('支付回调-初始化', $input);
  65. if ($sign == $string) {
  66. if (isset($input['billNo']) && $input['billNo']) {
  67. $key = 'billNo';
  68. } else {
  69. $key = 'merOrderId';
  70. }
  71. if (isset($this->config['prefix']) && $this->config['prefix']) {
  72. $input[$key] = str_replace($this->config['prefix'], '', $input[$key]);
  73. }
  74. if (isset($input['billPayment'])) {
  75. $input['billPayment'] = json_decode($input['billPayment'], true);
  76. if (isset($input['billPayment']['status'])) {
  77. $input['status'] = $input['billPayment']['status'];
  78. }
  79. }
  80. if (!isset($input['status'])) {
  81. echo 'FAILED';die;
  82. }
  83. $desc = '';
  84. if ($input['status'] == 'TRADE_SUCCESS') {
  85. # 成功
  86. } elseif ($input['status'] == 'TRADE_REFUND') {
  87. # 退款
  88. echo 'SUCCESS';die;
  89. } elseif ($input['status'] == 'TRADE_CLOSED') {
  90. $desc = '交易关闭';
  91. } elseif ($input['status'] == 'UNKNOWN') {
  92. $desc = '不明确的交易状态';
  93. } else {
  94. echo 'FAILED';die;
  95. }
  96. $this->updateOrder($input[$key], $input['totalAmount']);
  97. echo 'SUCCESS';die;
  98. } else {
  99. echo 'FAILED';die;
  100. }
  101. }
  102. private function getType($type)
  103. {
  104. switch ($type) {
  105. case 1:
  106. //小程序支付
  107. $type = 'MINI';
  108. break;
  109. case 2://扫码支付
  110. $type = 'APP';
  111. break;
  112. case 3://APP支付
  113. $type = 'APP';
  114. break;
  115. case 4://页面拉起支付
  116. $type = 'YUEDAN';
  117. break;
  118. }
  119. return $type;
  120. }
  121. /**
  122. * 获取统一下单的基本信息
  123. */
  124. public function order($account_id, $project_id, $uid, $username, $product_id, $name, $cash, $openid = false, $type = 1, $order_id = false, $other = false, $refer = false)
  125. {
  126. $trade_type = $this->getType($type);
  127. $order_id = $this->createOrder($uid, $username, $account_id, $project_id, $product_id, $name, $cash, $this->config['type'], $order_id);
  128. if (isset($this->config['prefix']) && $this->config['prefix']) {
  129. $request['merOrderId'] = $this->config['prefix'] . $order_id;
  130. } else {
  131. $request['merOrderId'] = $order_id;
  132. }
  133. $request['mid'] = $this->config['mid'];
  134. $request['tid'] = $this->config['tid'];
  135. $request['instMid'] = $trade_type . 'DEFAULT';
  136. $request['totalAmount'] = round($cash * 100, 2);
  137. //$request['totalAmount'] = 100;
  138. $request['subAppId'] = $this->config['sub_appid'];
  139. $request['requestTimestamp'] = date("Y-m-d H:i:s");
  140. $request['expireTime'] = date("Y-m-d H:i:s", time() + $this->config['timeout']);
  141. $request['notifyUrl'] = $this->config['notify'];
  142. $request['tradeType'] = $trade_type;
  143. if ($other) {
  144. if (!isset($other[0])) {
  145. $other = array($other);
  146. }
  147. $request['originalAmount'] = $request['totalAmount'];
  148. $request['platformAmount'] = $request['totalAmount'];
  149. $request['subOrders'] = array();
  150. foreach ($other as $k => $v) {
  151. $subOrders = array();
  152. if (isset($v['amount']) && $v['amount']) {
  153. $subOrders['totalAmount'] = $v['amount'];
  154. $request['platformAmount'] = round($request['platformAmount'] - $subOrders['totalAmount'], 2);
  155. } elseif (isset($v['per']) && $v['per']) {
  156. # 此处为兼容历史业务代码
  157. $v['per'] = $v['per'] && $v['per'] >= 0 ? $v['per'] : 0;
  158. $v['per'] = $v['per']/100;
  159. $request['platformAmount'] = round($request['totalAmount'] * $v['per'], 2);
  160. $subOrders['totalAmount'] = round($request['totalAmount'] - $request['platformAmount'], 2);
  161. break;
  162. } else {
  163. continue;
  164. }
  165. $subOrders['mid'] = $v['mid'];
  166. if (isset($this->config['prefix']) && $this->config['prefix']) {
  167. $subOrders['merOrderId'] = $this->config['prefix'] . $v['order_id'];
  168. } else {
  169. $subOrders['merOrderId'] = $v['order_id'];
  170. }
  171. $request['subOrders'][] = $subOrders;
  172. # 记录划付
  173. Dever::load('pay/yspay/cash')->add($order_id, $request, $subOrders);
  174. }
  175. if ($request['subOrders']) {
  176. $request['divisionFlag'] = true;
  177. }
  178. }
  179. if (!$openid) {
  180. # 测试的openid
  181. $request['subOpenId'] = 'ofBUV0RUoy_8C4VctZjrSDGzhUfY';
  182. } else {
  183. $request['subOpenId'] = $openid;
  184. }
  185. if ($type == 2) {
  186. # 二维码支付
  187. $request['instMid'] = 'QRPAYDEFAULT';
  188. $request['billNo'] = $request['merOrderId'];
  189. unset($request['merOrderId']);
  190. $result = Base::get_pay_code($request, $this->config);
  191. if (isset($result['billQRCode'])) {
  192. $result['request'] = $request;
  193. $result['payMsg'] = $result['billQRCode'];
  194. if ($other) {
  195. $result['other'] = $other;
  196. }
  197. $this->updateOrderParam($order_id, $result);
  198. return $result['payMsg'];
  199. }
  200. } elseif ($type == 1) {
  201. # 小程序支付
  202. $result = Base::pay($request, $this->config);
  203. if (isset($result['miniPayRequest'])) {
  204. $result['request'] = $request;
  205. $result['payMsg'] = $result['miniPayRequest'];
  206. unset($result['miniPayRequest']);
  207. if ($other) {
  208. $result['other'] = $other;
  209. }
  210. $this->updateOrderParam($order_id, $result);
  211. return $result['payMsg'];
  212. }
  213. } elseif ($type == 4) {
  214. if ($refer) {
  215. $request['returnUrl'] = $refer;
  216. }
  217. $result = Base::h5_pay($request, $this->config);
  218. return $result;
  219. }
  220. return false;
  221. }
  222. # 退款
  223. public function refund($order_id, $cash, $order, $refund_order_id = false)
  224. {
  225. if (isset($this->config['prefix']) && $this->config['prefix']) {
  226. $request['merOrderId'] = $this->config['prefix'] . $order_id;
  227. if ($refund_order_id) {
  228. $request['refundOrderId'] = $this->config['prefix'] . $refund_order_id;
  229. }
  230. } else {
  231. $request['merOrderId'] = $order_id;
  232. if ($refund_order_id) {
  233. $request['refundOrderId'] = $refund_order_id;
  234. }
  235. }
  236. $request['mid'] = $this->config['mid'];
  237. $request['tid'] = $this->config['tid'];
  238. $request['instMid'] = 'MINIDEFAULT';
  239. if (isset($order['param']['targetOrderId'])) {
  240. $request['targetOrderId'] = $order['param']['targetOrderId'];
  241. }
  242. $request['subAppId'] = $this->config['appid'];
  243. $request['requestTimestamp'] = date("Y-m-d H:i:s");
  244. $request['refundAmount'] = round($cash * 100, 2);
  245. if (isset($order['param']['other']) && $order['param']['other']) {
  246. $other = $order['param']['other'];
  247. if (!isset($other[0])) {
  248. $other = array($other);
  249. }
  250. $request['platformAmount'] = $request['refundAmount'];
  251. $request['subOrders'] = array();
  252. foreach ($other as $k => $v) {
  253. $subOrders = array();
  254. if (isset($v['amount']) && $v['amount']) {
  255. $subOrders['totalAmount'] = $v['amount'];
  256. $request['platformAmount'] = round($request['platformAmount'] - $subOrders['totalAmount'], 2);
  257. } elseif (isset($v['per']) && $v['per']) {
  258. $v['per'] = $v['per'] && $v['per'] >= 0 ? $v['per'] : 0;
  259. $v['per'] = $v['per']/100;
  260. $request['platformAmount'] = round($request['refundAmount'] * $v['per'], 2);
  261. $subOrders['totalAmount'] = round($request['totalAmount'] - $request['platformAmount'], 2);
  262. } else {
  263. continue;
  264. }
  265. $subOrders['mid'] = $other['mid'];
  266. if (isset($this->config['prefix']) && $this->config['prefix']) {
  267. $subOrders['merOrderId'] = $this->config['prefix'] . $v['order_id'];
  268. if ($refund_order_id) {
  269. $subOrders['refundOrderId'] = $this->config['prefix'] . $refund_order_id;
  270. }
  271. } else {
  272. $subOrders['merOrderId'] = $v['order_id'];
  273. if ($refund_order_id) {
  274. $subOrders['refundOrderId'] = $refund_order_id;
  275. }
  276. }
  277. $request['subOrders'][] = $subOrders;
  278. }
  279. }
  280. $account = Dever::db('pay/account')->find($order['account_id']);
  281. $method = 'refund';
  282. if ($account && $account['system_source'] == 4) {
  283. $method = 'code_refund';
  284. $request['billNo'] = $request['merOrderId'];
  285. $request['instMid'] = 'QRPAYDEFAULT';
  286. $request['billDate'] = date('Y-m-d');
  287. }
  288. $result = Base::$method($request, $this->config);
  289. if (isset($result['refundStatus']) && $result['refundStatus'] == 'SUCCESS') {
  290. return true;
  291. }
  292. return false;
  293. }
  294. # 查询
  295. public function query($order_id)
  296. {
  297. $request['merOrderId'] = $order_id;
  298. $request['mid'] = $this->config['mchid'];
  299. $request['tid'] = $this->config['key'];
  300. $request['instMid'] = 'MINIDEFAULT';
  301. $request['requestTimestamp'] = date("Y-m-d H:i:s");
  302. $result = Base::refund($request, $this->config);
  303. return $result;
  304. }
  305. # 关闭订单
  306. public function close($order_id)
  307. {
  308. $request['merOrderId'] = $order_id;
  309. $request['mid'] = $this->config['mchid'];
  310. $request['tid'] = $this->config['key'];
  311. $request['instMid'] = 'MINIDEFAULT';
  312. $request['requestTimestamp'] = date("Y-m-d H:i:s");
  313. $result = Base::close($request, $this->config);
  314. return $result;
  315. }
  316. /**
  317. * 获取二维码支付
  318. */
  319. public function qrcode($order, $refer)
  320. {
  321. $result['type'] = 'qrcode';
  322. $result['url'] = $order;
  323. return $result;
  324. }
  325. /**
  326. * 获取小程序支付
  327. */
  328. public function applet($order)
  329. {
  330. $result = array();
  331. if (isset($order['package'])) {
  332. $prepay_id = str_replace('prepay_id=', '', $order['package']);
  333. $result['time'] = $order['timeStamp'];
  334. $result['nonce_str'] = $order['nonceStr'];
  335. $result['prepay_id'] = $prepay_id;
  336. $result['sign_type'] = $order['signType'];
  337. $result['sign'] = $order['paySign'];
  338. $result['type'] = 'applet';
  339. }
  340. return $result;
  341. }
  342. /**
  343. * 获取页面支付 去收银台
  344. */
  345. public function page($order, $refer)
  346. {
  347. return $order;
  348. }
  349. }
  350. class Base
  351. {
  352. static $test_host = 'https://test-api-open.chinaums.com/';
  353. static $host = 'https://api-mop.chinaums.com/';
  354. static $signMethod = 'SHA256'; //签名方式
  355. # 获取token
  356. static $token_url = 'v1/token/access';
  357. # 微信下单支付
  358. static $pay_wechat_url = 'v1/netpay/wx/unified-order';
  359. # 支付宝下单支付
  360. static $pay_alipay_url = 'v1/netpay/trade/create';
  361. # 云闪付下单支付
  362. static $pay_uac_url = 'v1/netpay/uac/mini-order';
  363. # 交易查询
  364. static $query_url = 'v1/netpay/query';
  365. # 退款
  366. static $refund_url = 'v1/netpay/refund';
  367. # 退款查询
  368. static $refund_query_url = 'v1/netpay/refund-query';
  369. # 订单关闭
  370. static $close_url = 'v1/netpay/close';
  371. # 二维码支付
  372. static $qrcode_url = 'v1/netpay/bills/get-qrcode';
  373. # 二维码支付退款
  374. static $qrcode_refund_url = 'v1/netpay/bills/refund';
  375. # h5支付
  376. static $h5_url = 'v1/netpay/webpay/pay';
  377. # h5支付退款
  378. static $h5_refund_url = 'v1/netpay/wx/app-pre-order';
  379. //===================== 支付相关 ==============================
  380. /**
  381. * 支付交易
  382. */
  383. static public function pay($param, $config)
  384. {
  385. $url = self::$pay_wechat_url;
  386. $result = self::get($url, $param, $config);
  387. return $result;
  388. }
  389. /**
  390. * h5支付
  391. */
  392. static public function h5_pay($param, $config)
  393. {
  394. $url = self::$h5_url;
  395. $result = self::get($url, $param, $config);
  396. return $result;
  397. }
  398. /**
  399. * 获取支付二维码
  400. */
  401. static public function get_pay_code($param, $config)
  402. {
  403. $url = self::$qrcode_url;
  404. $result = self::get($url, $param, $config);
  405. return $result;
  406. }
  407. /**
  408. * 二维码交易退款
  409. */
  410. static public function code_refund($param, $config)
  411. {
  412. $url = self::$qrcode_refund_url;
  413. $result = self::get($url, $param, $config);
  414. return $result;
  415. }
  416. /**
  417. * 支付撤销
  418. */
  419. static public function close()
  420. {
  421. $url = self::$close_url;
  422. $result = self::get($url, $param, $config);
  423. return $result;
  424. }
  425. /**
  426. * 交易退款
  427. */
  428. static public function refund($param, $config)
  429. {
  430. $url = self::$refund_url;
  431. $result = self::get($url, $param, $config, false);
  432. return $result;
  433. }
  434. /**
  435. * 交易查询
  436. */
  437. static public function query()
  438. {
  439. $url = self::$query_url;
  440. $result = self::get($url, $param, $config);
  441. return $result;
  442. }
  443. /**
  444. * 交易退款查询
  445. */
  446. static public function refundQuery()
  447. {
  448. $url = self::$refund_query_url;
  449. $result = self::get($url, $param, $config);
  450. return $result;
  451. }
  452. //====================== 获取调用凭证===========================
  453. /**
  454. * 通用调用凭证获取
  455. * 默认使用token方式,使用签名方式需要传入参数
  456. */
  457. static public function getAuth($type = 'token', $param, $config)
  458. {
  459. if ($type === 'token') {
  460. return self::getAccessTokenByToken($config);
  461. } elseif ($type === 'form') {
  462. return self::getAccessTokenByForm($param, $config);
  463. }
  464. return self::getAccessTokenBySig($param, $config);
  465. }
  466. /**
  467. * 方式一,OPEN-ACCESS-TOKEN方式
  468. */
  469. static function getAccessTokenByToken($config)
  470. {
  471. $param = [
  472. 'appId' => $config['appid'],
  473. 'timestamp' => date('YmdHis'),
  474. 'nonce' => md5(uniqid(microtime(true),true)),
  475. 'signMethod' => self::$signMethod,
  476. ];
  477. $param['signature'] = self::signature($param, $config['appsecret']);
  478. $result = self::get(self::$token_url, $param, $config);
  479. if (isset($result['errCode']) && isset($result['accessToken'])) {
  480. return 'OPEN-ACCESS-TOKEN AccessToken='.$result['accessToken'];
  481. }
  482. return '';
  483. }
  484. /**
  485. * 方式二,OPEN-BODY-SIG方式
  486. */
  487. static function getAccessTokenBySig($data, $config)
  488. {
  489. $param = [
  490. 'AppId' => $config['appid'],
  491. 'Timestamp' => date('YmdHis'),
  492. 'Nonce' => md5(uniqid(microtime(true),true))
  493. ];
  494. return 'OPEN-BODY-SIG AppId="'.$param['AppId'].'", Timestamp="'.$param['Timestamp'].'", Nonce="'.$param['Nonce'].'", Signature="'.self::signature2($data, $param, $config['appsecret']).'"';
  495. }
  496. /**
  497. * 方式三,OPEN-FORM-PARAM方式
  498. */
  499. static function getAccessTokenByForm($data, $config)
  500. {
  501. $content = Dever::json_encode($data);
  502. $param = [
  503. 'appId' => $config['appid'],
  504. 'timestamp' => date('YmdHis'),
  505. 'nonce' => md5(uniqid(microtime(true),true)),
  506. 'authorization' => 'OPEN-FORM-PARAM',
  507. 'content' => $content,
  508. ];
  509. $param['signature'] = urlencode(self::signature3($param, $config['appsecret']));
  510. $param['content'] = urlencode($param['content']);
  511. return $param;
  512. }
  513. /**
  514. * 计算签名,方式一
  515. */
  516. static function signature($param, $appsecret)
  517. {
  518. return bin2hex(hash(self::$signMethod, $param['appId'].$param['timestamp'].$param['nonce'].$appsecret, true));
  519. }
  520. /**
  521. * 计算签名,方式二
  522. */
  523. static function signature2($data, $param, $appsecret)
  524. {
  525. $str = bin2hex(hash('sha256', Dever::json_encode($data), true));
  526. return base64_encode(hash_hmac('sha256', $param['AppId'].$param['Timestamp'].$param['Nonce'].$str, $appsecret, true));
  527. }
  528. /**
  529. * 计算签名,方式三
  530. */
  531. static function signature3($param, $appsecret)
  532. {
  533. $str = bin2hex(hash('sha256', $param['content'], true));
  534. return base64_encode(hash_hmac('sha256', $param['appId'].$param['timestamp'].$param['nonce'].$str, $appsecret, true));
  535. }
  536. /**
  537. * 获取信息
  538. */
  539. static function get($url, $param, $config, $state = true)
  540. {
  541. $url = $config['box'] == 1 ? self::$host . $url : self::$test_host . $url;
  542. if (strstr($url, 'webpay')) {
  543. $url .= '?';
  544. $param = self::getAuth('form', $param, $config);
  545. foreach ($param as $k => $v) {
  546. $url .= '&' . $k . '=' . $v;
  547. }
  548. $url = str_replace('?&', '?', $url);
  549. return $url;
  550. } else {
  551. $header = array();
  552. $header['Authorization'] = self::getAuth('sig', $param, $config);
  553. $result = Dever::curl($url, $param, 'post', true, $header);
  554. }
  555. if (strstr($result, '<html><head>')) {
  556. Dever::alert('系统错误');
  557. }
  558. $result = Dever::json_decode($result);
  559. if (isset($result['errCode'])) {
  560. if (!$state) {
  561. return $result;
  562. }
  563. if ($result['errCode'] == '0000' || $result['errCode'] == 'SUCCESS') {
  564. return $result;
  565. } elseif (isset($result['errInfo'])) {
  566. Dever::alert('操作失败,请联系管理员');
  567. Dever::alert($result['errInfo']);
  568. } elseif (isset($result['errMsg'])) {
  569. Dever::alert('操作失败,请联系管理员');
  570. Dever::alert($result['errMsg']);
  571. }
  572. } else {
  573. Dever::alert('系统错误');
  574. }
  575. return $result;
  576. }
  577. }