ChannelRecharge.php 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597
  1. <?php
  2. /**
  3. * 渠道充值接口控制器
  4. *
  5. */
  6. namespace app\guildapi\controller;
  7. use app\guildapi\controller\Guild;
  8. use app\common\model\ChannelRecharge as ChannelRechargeModel;
  9. use app\common\library\WeixinPay;
  10. use think\Db;
  11. use think\Config;
  12. use app\common\model\Setting;
  13. use think\Exception;
  14. class ChannelRecharge extends Guild {
  15. protected $nowTime;
  16. protected $payRequestLimit = 5; //重复下单的限制时间
  17. protected $redis; //redis的句柄对象
  18. /**
  19. * 不进行父类的登录验证,所以增加构造方法重写了父类的初始化方法
  20. */
  21. public function _initialize()
  22. {
  23. parent::_initialize();
  24. $this->nowTime = NOW_TIMESTAMP;
  25. $this->redis = \think\Cache::store('default')->handler();
  26. }
  27. /**
  28. * 我的充值列表
  29. * @return [type] [description]
  30. */
  31. public function index()
  32. {
  33. //判断当前账号是否有此功能
  34. if(!in_array($this->_channelLevel,[1,2])){
  35. $this->jsonResult('', 0, '您无权限使用该功能');
  36. }
  37. $list_rows = $this->input('list_rows',10);
  38. $page = $this->input('page',1);
  39. $type = $this->input('type','0','intval'); //1(充值收入),2(充值支出),3(直充),4(结算充值收入),5(结算充值支出)
  40. $account = $this->input('account','','trim'); //收入账号
  41. $apply_begin_time = $this->input('apply_begin_time','','trim');
  42. $apply_end_time = $this->input('apply_end_time','','trim');
  43. $finish_begin_time = $this->input('finish_begin_time','','trim');
  44. $finish_end_time = $this->input('finish_end_time','','trim');
  45. $condition = [];
  46. if($account){
  47. $condition['channel_name'] = $account;
  48. }
  49. if($type==1){
  50. $condition['channel_id'] = $this->_channelId;
  51. $condition['recharge_type'] = 1;
  52. }
  53. else if($type==2){
  54. $condition['send_channel_id'] = $this->_channelId;
  55. $condition['recharge_type'] = 1;
  56. }
  57. else if($type==3){
  58. $condition['channel_id'] = $this->_channelId;
  59. $condition['recharge_type'] = 2;
  60. }
  61. else if($type==4){
  62. $condition['channel_id'] = $this->_channelId;
  63. $condition['recharge_type'] = 3;
  64. }
  65. else if($type==5){
  66. $condition['send_channel_id'] = $this->_channelId;
  67. $condition['recharge_type'] = 3;
  68. }
  69. //申请开始时间和结束时间不为空时
  70. if ($apply_begin_time != '' && $apply_end_time != '') {
  71. $condition['create_time'] = [
  72. ['>=', strtotime($apply_begin_time)],
  73. ['<=', strtotime($apply_end_time . ' 23:59:59')],
  74. ];
  75. } //开始时间不为空时
  76. elseif ($apply_begin_time != '') {
  77. $condition['create_time'] = ['>=', strtotime($apply_begin_time)];
  78. } //结束时间不为空时
  79. elseif ($apply_end_time != '') {
  80. $condition['create_time'] = ['<=', strtotime($apply_end_time . ' 23:59:59')];
  81. }
  82. //到账开始时间和结束时间不为空时
  83. if ($finish_begin_time != '' && $finish_end_time != '') {
  84. $condition['finish_time'] = [
  85. ['>=', strtotime($finish_begin_time)],
  86. ['<=', strtotime($finish_end_time . ' 23:59:59')],
  87. ];
  88. } //开始时间不为空时
  89. elseif ($finish_begin_time != '') {
  90. $condition['finish_time'] = ['>=', strtotime($finish_begin_time)];
  91. } //结束时间不为空时
  92. elseif ($finish_end_time != '') {
  93. $condition['finish_time'] = ['<=', strtotime($finish_end_time . ' 23:59:59')];
  94. }
  95. // var_dump($condition);
  96. $rechargeList = model('ChannelRecharge')
  97. ->where($condition)
  98. ->whereRaw('channel_id='.$this->_channelId.' or send_channel_id='.$this->_channelId)
  99. ->paginate(['list_rows'=>$list_rows,'page'=>$page])
  100. ->toArray();
  101. // echo model('ChannelRecharge')->getLastSql()."-----lastsql------<br>";
  102. $this->jsonResult($rechargeList, 20000, '获取列表成功');
  103. }
  104. /**
  105. * 充值审核列表
  106. * @return [type] [description]
  107. */
  108. public function checklist()
  109. {
  110. //判断当前账号是否有此功能
  111. if(!in_array($this->_channelLevel,[1])){
  112. $this->jsonResult('', 0, '您无权限使用该功能');
  113. }
  114. $list_rows = input('list_rows',10);
  115. $page = input('page',1);
  116. $account = $this->input('account','','trim');
  117. $orderid = $this->input('orderid','','trim');
  118. $apply_begin_time = $this->input('apply_begin_time','','trim');
  119. $apply_end_time = $this->input('apply_end_time','','trim');
  120. $condition = [];
  121. $condition['send_channel_id'] = $this->_channelId;
  122. if($orderid){
  123. $condition['orderid'] = $orderid;
  124. }
  125. if($account){
  126. $condition['channel_name'] = $account;
  127. }
  128. //申请开始时间和结束时间不为空时
  129. if ($apply_begin_time != '' && $apply_end_time != '') {
  130. $condition['create_time'] = [
  131. ['>=', strtotime($apply_begin_time)],
  132. ['<=', strtotime($apply_end_time . ' 23:59:59')],
  133. ];
  134. } //开始时间不为空时
  135. elseif ($apply_begin_time != '') {
  136. $condition['create_time'] = ['>=', strtotime($apply_begin_time)];
  137. } //结束时间不为空时
  138. elseif ($apply_end_time != '') {
  139. $condition['create_time'] = ['<=', strtotime($apply_end_time . ' 23:59:59')];
  140. }
  141. $rechargeList = model('ChannelRecharge')
  142. ->where($condition)
  143. ->paginate(['list_rows'=>$list_rows,'page'=>$page])
  144. ->toArray();
  145. $this->jsonResult($rechargeList, 20000, '获取列表成功');
  146. }
  147. /**
  148. * 充值审核(查看)
  149. */
  150. public function audit(){
  151. if ($this->request->isPost()) {
  152. $id = intval($this->input('id')); //渠道ID
  153. if(!in_array($this->_channelLevel,[1])){
  154. $this->jsonResult('', 0, '您不能进行该操作');
  155. }
  156. if(!$id){
  157. $this->jsonResult('', 0, '请选择要审核的记录');
  158. }
  159. $rechargeInfo = model('ChannelRecharge')->where(['id'=>$id,'send_channel_id'=>$this->_channelId])->find();
  160. if(empty($rechargeInfo)){
  161. $this->jsonResult('', 0, '记录不存在或您无权限操作');
  162. }
  163. $this->jsonResult($rechargeInfo, 20000, '获取记录成功');
  164. exit;
  165. }
  166. else{
  167. $this->jsonResult('', 0, '非法请求');
  168. }
  169. }
  170. //充值审核(操作)
  171. function doAudit(){
  172. if ($this->request->isPost()) {
  173. $id = intval($this->input('id')); //渠道ID
  174. $status = intval($this->input('status')); //审核状态:1(审核通过),2(审核不通过)
  175. $remark = $this->input('remark','','trim'); //审核备注
  176. if(!in_array($this->_channelLevel,[1])){
  177. $this->jsonResult('', 0, '您不能进行该操作');
  178. }
  179. if(!$id){
  180. $this->jsonResult('', 0, '请选择要审核的记录');
  181. }
  182. if($status<>1 && $status<>2){
  183. $this->jsonResult('', 0, '非法审核状态');
  184. }
  185. $rechargeInfo = model('ChannelRecharge')->where(['id'=>$id,'send_channel_id'=>$this->_channelId])->find();
  186. if(empty($rechargeInfo)){
  187. $this->jsonResult('', 0, '记录不存在或您无权限操作');
  188. }
  189. else if($rechargeInfo['status']<>0){
  190. $this->jsonResult('', 0, '该记录已审核过');
  191. }
  192. $channelInfo = model("Channel")->where(['id'=>$this->_channelId])->find();
  193. if($channelInfo){
  194. if($channelInfo['amount'] < $rechargeInfo['amount']){
  195. $this->jsonResult('', 0, '您当前余额不足,不能进行审核发币');
  196. }
  197. }
  198. else{
  199. $this->jsonResult('', 0, '您的账号有异常,请联系管理员');
  200. }
  201. $auditData = array();
  202. $auditData['id'] = $id;
  203. $auditData['status'] = $status;
  204. $auditData['finish_time'] = NOW_TIMESTAMP;
  205. $auditData['check_remark'] = $remark;
  206. $auditData['check_admin_type'] = 2;
  207. $auditData['check_admin_name'] = $this->_channelName;
  208. Db::startTrans();
  209. try {
  210. //审核通过
  211. if($status==1){
  212. $detData = array();
  213. $detData['channel_id'] = $this->_channelId;
  214. $detData['channel_name'] = $this->_channelName;
  215. $detData['change_amount'] = -$rechargeInfo['amount'];
  216. $detData['account_type'] = 1; //通用账户
  217. $detData['type'] = 5; //充值支出
  218. $detData['out_orderid'] = $rechargeInfo['orderid'];
  219. $detData['create_time'] = NOW_TIMESTAMP;
  220. $insertDetId = model('ChannelAccountDet')->insertGetId($detData);
  221. if ( !$insertDetId) {
  222. throw new Exception("添加账户变动明细失败");
  223. }
  224. $updData = array();
  225. $updData['amount'] = Db::raw("amount-".$rechargeInfo['amount']);
  226. $updData['update_time'] = time();
  227. $updFromResult = model('Channel')->where(['id'=>$this->_channelId,'amount'=>array('egt',$rechargeInfo['amount'])])->update($updData);
  228. if (!$updFromResult) {
  229. throw new Exception("账户金额变动失败");
  230. }
  231. $detData = array();
  232. $detData['channel_id'] = $rechargeInfo['channel_id'];
  233. $detData['channel_name'] = $rechargeInfo['channel_name'];
  234. $detData['change_amount'] = $rechargeInfo['amount'];
  235. $detData['account_type'] = 1; //通用账户
  236. $detData['type'] = 4; //充值收入
  237. $detData['out_orderid'] = $rechargeInfo['orderid'];
  238. $detData['create_time'] = NOW_TIMESTAMP;
  239. $insertDetId = model('ChannelAccountDet')->insertGetId($detData);
  240. if ( !$insertDetId) {
  241. throw new Exception("添加账户变动明细失败");
  242. }
  243. $updData = array();
  244. $updData['amount'] = Db::raw("amount+".$rechargeInfo['amount']);
  245. $updData['update_time'] = time();
  246. $updToResult = model('Channel')->where(['id'=>$rechargeInfo['channel_id']])->update($updData);
  247. if (!$updToResult) {
  248. throw new Exception("账户金额变动失败");
  249. }
  250. $auditData['finish_status'] = 1;
  251. $result = model('ChannelRecharge')->where(['id'=>$id,'status'=>array('in',[0])])->update($auditData);
  252. if (!$result) {
  253. throw new Exception("充值审核失败");
  254. }
  255. }
  256. else if($status==2){ //审核不通过
  257. $result = model('ChannelRecharge')->where(['id'=>$id,'status'=>array('in',[0])])->update($auditData);
  258. if (!$result) {
  259. throw new Exception("充值审核失败");
  260. }
  261. }
  262. Db::commit();
  263. } catch (\Exception $e) {
  264. Db::rollback();
  265. $this->jsonResult('', 0, '添加失败: ' . $e->getMessage());
  266. }
  267. $this->jsonResult('', 20000, '审核成功');
  268. exit;
  269. }
  270. else{
  271. $this->jsonResult('', 0, '非法请求');
  272. }
  273. }
  274. /**
  275. * 充值处理
  276. */
  277. public function recharge()
  278. {
  279. if ($this->request->isPost()) {
  280. $amount = $this->input('amount'); //充值金额
  281. $real_amount = $this->input('real_amount'); //支付金额
  282. $recharge_type = $this->input('recharge_type'); //充值方式:1(申请),2(直充),3(结算币充值)
  283. $paytype = $this->input('paytype'); //支付类型:zfb(支付宝),wxpay(微信)
  284. $out_order_no = $this->input('out_order_no'); //交易凭证
  285. $remark = $this->input('remark'); //备注
  286. $orderid = 'R'.makeOrderid();
  287. $checkResult = $this->validate($this->input,'ChannelRecharge.add');
  288. if (true !== $checkResult) {
  289. $this->jsonResult('', 0, $checkResult);
  290. }
  291. //判断当前账号是否有充值权限
  292. if(!in_array($this->_channelLevel,[1,2])){
  293. $this->jsonResult('', 0, '您不能进行充值');
  294. }
  295. if(!in_array($recharge_type,[1,2,3])){
  296. $this->jsonResult('', 0, '非正确的充值方式');
  297. }
  298. else{
  299. if($recharge_type==2 && !in_array($paytype,['zfb','wxpay'])){
  300. $this->jsonResult('', 0, '非正确的支付类型');
  301. }
  302. }
  303. if(abs(intval($real_amount*100)/100-$real_amount) > 0.01){
  304. $this->jsonResult('', 0, '请正确填写支付金额!');
  305. }
  306. else{
  307. //判断支付金额
  308. $condis = array();
  309. $condis['channel_id'] = $this->_channelId;
  310. $condis['begin_time'] = array('elt',$this->nowTime);
  311. $condis['end_time'] = array('egt',$this->nowTime);
  312. $rechargeRatio = model("ChannelRechargeRatio")->where($condis)->find();
  313. if(!empty($rechargeRatio) && $rechargeRatio['ratio']){
  314. $rechargeRatio = $rechargeRatio['ratio'];
  315. }
  316. else{
  317. $rechargeRatio = 100;
  318. }
  319. $discountAmt = floatval($amount*$rechargeRatio/100);
  320. if($discountAmt <> $real_amount){
  321. $this->jsonResult('', 0, '充值金额异常,请刷新页面后重新充值');
  322. }
  323. }
  324. $channelInfo = model("Channel")->where(['id'=>$this->_channelId])->find();
  325. if($channelInfo && $channelInfo['parent_id']){
  326. if($recharge_type==3 && $channelInfo['js_amount']<$amount){
  327. $this->jsonResult('', 0, '您的结算币余额不足');
  328. }
  329. }
  330. else{
  331. $this->jsonResult('', 0, '您的账号有异常,请联系管理员');
  332. }
  333. //指定时间内,禁止重复下单
  334. if(!requestDuplicateCheck('recharge_pay_duplicate_'.$this->_channelId,$this->payRequestLimit)){
  335. $this->jsonResult('', 0, '充值请求过多,请于'.$this->payRequestLimit.'s以后,再次进行充值操作');
  336. }
  337. $rechargeData = array();
  338. $rechargeData['orderid'] = $orderid;
  339. $rechargeData['channel_id'] = $this->_channelId;
  340. $rechargeData['channel_name'] = $this->_channelName;
  341. if($this->_channelLevel==1){
  342. $rechargeData['send_channel_id'] = '0';
  343. $rechargeData['send_channel_name'] = '平台';
  344. }
  345. else if($this->_channelLevel==2){
  346. $parentChannelInfo = model("Channel")->where(['id'=>$channelInfo['parent_id']])->find();
  347. $rechargeData['send_channel_id'] = $parentChannelInfo['id'];
  348. $rechargeData['send_channel_name'] = $parentChannelInfo['name'];
  349. }
  350. $rechargeData['amount'] = $amount;
  351. $rechargeData['real_amount'] = $real_amount;
  352. $rechargeData['recharge_type'] = $recharge_type;
  353. $rechargeData['paytype'] = $paytype;
  354. $rechargeData['out_order_no'] = $out_order_no;
  355. $rechargeData['remark'] = $remark;
  356. $rechargeData['status'] = 0;
  357. $rechargeData['create_time'] = time();
  358. // 启动事务
  359. Db::startTrans();
  360. try{
  361. $result = ''; //返回值
  362. //结算币充值
  363. if($recharge_type==3){
  364. $rechargeData['status'] = 1;
  365. $insertRechargeId = model("ChannelRecharge")->insert($rechargeData);
  366. if(!$insertRechargeId){
  367. throw new Exception("创建订单失败! ");
  368. }
  369. $detData = array();
  370. $detData['channel_id'] = $this->_channelId;
  371. $detData['channel_name'] = $this->_channelName;
  372. $detData['change_amount'] = -$amount;
  373. $detData['account_type'] = 2; //结算账户
  374. $detData['type'] = 7; //结算充值
  375. $detData['out_orderid'] = $orderid;
  376. $detData['create_time'] = NOW_TIMESTAMP;
  377. $insertDetId = model('ChannelAccountDet')->insertGetId($detData);
  378. if ( !$insertDetId) {
  379. throw new Exception("添加账户变动明细失败");
  380. }
  381. $updData = array();
  382. $updData['js_amount'] = Db::raw("js_amount-".$amount);
  383. $updData['update_time'] = time();
  384. $updResult = model('Channel')->where(['id'=>$this->_channelId,'js_amount'=>array('egt',$amount)])->update($updData);
  385. if (!$updResult) {
  386. throw new Exception("账户金额变动失败");
  387. }
  388. $detData = array();
  389. $detData['channel_id'] = $this->_channelId;
  390. $detData['channel_name'] = $this->_channelName;
  391. $detData['change_amount'] = $amount;
  392. $detData['account_type'] = 1; //通用账户
  393. $detData['type'] = 4; //充值收入
  394. $detData['out_orderid'] = $orderid;
  395. $detData['create_time'] = NOW_TIMESTAMP;
  396. $insertDetId = model('ChannelAccountDet')->insertGetId($detData);
  397. if ( !$insertDetId) {
  398. throw new Exception("添加账户变动明细失败");
  399. }
  400. $updData = array();
  401. $updData['amount'] = Db::raw("amount+".$amount);
  402. $updData['update_time'] = time();
  403. $updResult = model('Channel')->where(['id'=>$this->_channelId])->update($updData);
  404. if (!$updResult) {
  405. throw new Exception("账户金额变动失败");
  406. }
  407. }
  408. else{
  409. $insertRechargeId = model("ChannelRecharge")->insert($rechargeData);
  410. if(!$insertRechargeId){
  411. throw new Exception("创建订单失败! ");
  412. }
  413. }
  414. //第三方支付用的商品简单描述 (去除&+等特殊字符)
  415. $payBody = "用户充值";
  416. //支付方式是支付宝或者支付宝混合支付时
  417. if($paytype=='zfb'){
  418. //支付宝支付参数
  419. $alipayParam = $this->getAlipayAopParam($orderid,$rechargeData['real_amount'],$payBody);
  420. $result = ['alipay_param'=>$alipayParam];
  421. }
  422. //支付方式是微信官方h5支付或者微信官方h5混合支付时
  423. elseif($paytype=='wxpay')
  424. {
  425. $wxpayh5_param = $this->getWxpayH5Param($orderid,$rechargeData['real_amount'],$payBody);
  426. $result = ['wxpayh5_param'=>$wxpayh5_param];
  427. }
  428. $this->redis->del('recharge_pay_duplicate_'.$this->_channelId);
  429. // 提交事务
  430. Db::commit();
  431. } catch (\Exception $e) {
  432. // 回滚事务
  433. Db::rollback();
  434. $this->jsonResult('', 0, '订单生成失败'.$e->getMessage());
  435. }
  436. $result['orderid'] = $orderid;
  437. $this->jsonResult($result, 20000, '订单生成成功');
  438. exit;
  439. }
  440. else{
  441. $this->jsonResult('', 0, '非法请求');
  442. exit;
  443. }
  444. }
  445. /**
  446. * 获取支付宝支付参数
  447. *
  448. * @param string $orderid 订单号
  449. * @param float $real_amount 支付金额
  450. * @param string $productname 商品名称
  451. * @param string $productdesc 描述
  452. *
  453. * @return string 支付参数字符串
  454. */
  455. private function getAlipayAopParam($orderid,$real_amount,$productname,$productdesc='')
  456. {
  457. //Alipay Aop Sdk支付发起
  458. vendor('alipayAop.AopSdk');
  459. $aop = new \AopClient();
  460. $aop->gatewayUrl = 'https://openapi.alipay.com/gateway.do';
  461. $aop->appId = Config::get('alipayAop')['appId'];
  462. $aop->rsaPrivateKey = file_get_contents(Config::get('alipayAop')['private_key']);
  463. $aop->alipayrsaPublicKey = file_get_contents(Config::get('alipayAop')['alipay_public_key']);
  464. $aop->apiVersion = '1.0';
  465. $aop->signType = Config::get('alipayAop')['sign_type'];
  466. $aop->postCharset = 'utf-8';
  467. $aop->format = 'json';
  468. $request = new \AlipayTradeAppPayRequest();
  469. $bizcontent = array();
  470. $bizcontent['subject'] = preg_replace("/[\&\+]+/", '', $productname); // 主题(过滤特殊字符)
  471. $bizcontent['body'] = preg_replace("/[\&\+]+/", '', $productdesc); // 商品描述信息(过滤特殊字符)
  472. $bizcontent['out_trade_no'] = $orderid; // 订单号
  473. $bizcontent['timeout_express'] = '30m'; // 超时时间
  474. $bizcontent['total_amount'] = $real_amount; // 支付金额
  475. $bizcontent['product_code'] = 'QUICK_MSECURITY_PAY'; // 支付方式
  476. $request->setBizContent(json_encode($bizcontent));
  477. $request->setNotifyUrl(Config::get('alipayAop')['notify_url']);
  478. $result = $aop->sdkExecute($request);
  479. // echo htmlspecialchars($result);
  480. return $result;
  481. }
  482. /**
  483. * 微信官方h5支付
  484. *
  485. * @param string $orderid 订单号
  486. * @param float $real_amount 支付金额
  487. * @param string $body 商品名称
  488. *
  489. * @return array 支付参数数组
  490. */
  491. private function getWxpayH5Param($orderid,$real_amount,$body)
  492. {
  493. $pay_return = false;
  494. $wxPay = new WeixinPay;
  495. $params['appid'] = Config::get('wxpay-h5')['appid'];
  496. $params['mch_id'] = Config::get('wxpay-h5')['mch_id'];
  497. $params['nonce_str'] = random(10);
  498. $params['body'] = $body;
  499. $params['out_trade_no'] = $orderid;
  500. $params['total_fee'] = $real_amount*100; // 支付金额,以分为单位
  501. $params['spbill_create_ip'] = $this->request->ip();
  502. $params['notify_url'] = Config::get('wxpay-h5')['notify_url'];
  503. $params['trade_type'] = 'MWEB';
  504. $params['scene_info'] = '{"h5_info":{"type":"Wap","wap_url":"http://m.weilongwl.com","wap_name":"麻花网络游戏"}}';
  505. //获取签名数据
  506. $params['sign'] = $wxPay->MakeSign($params,Config::get('wxpay-h5')['key']);
  507. $xml = dataToXml($params);
  508. $response = $wxPay->postXmlCurl($xml);
  509. if (!$response) {
  510. return false;
  511. }
  512. $result = $wxPay->xmlToArray($response);
  513. if( array_key_exists("return_code", $result) && $result["return_code"] == "SUCCESS" && array_key_exists("result_code", $result) && $result["result_code"] == "SUCCESS")
  514. {
  515. $pay_return['prepay_id'] = $result['prepay_id'];
  516. $pay_return['trade_type'] = $result['trade_type'];
  517. $pay_return['mweb_url'] = $result['mweb_url'];
  518. $pay_return['referer'] = Config::get('wxpay-h5')['referer'];
  519. }
  520. else{
  521. throw new \Exception(' 错误代码:'.$result["err_code"].' 错误代码描述:'.$result["err_code_des"]);
  522. }
  523. return $pay_return;
  524. }
  525. }