payConfig($model, $cost, ['supplier' => 1, 'agent' => 2, 'guide' => 3][$type]); if (empty($pay['code_url'])) { if (isset($pay['result_code'], $pay['err_code_des']) && $pay['result_code'] != 'SUCCESS') { $msg = $pay['err_code_des']; } else { $msg = $pay['return_msg'] ?? '获取支付信息失败'; } $js = "Dcat.swal.info('支付:$msg', null);"; } else { $ajax_url = admin_url('is_pay'); $js = <<

入驻费:¥{$cost}元

', '请微信扫码支付,请勿关闭页面', { type: null, imageWidth: 240, imageHeight: 240, animation: false, // confirmButtonText: '我已完成支付,刷新', showConfirmButton: false, allowOutsideClick: false, allowEscapeKey: false, onOpen: function () { $('#qrcode').qrcode({text:'{$pay["code_url"]}', width:240, height:240}); if (window.timer) { clearInterval(window.timer); } window.timer = setInterval(function () { $.ajax({ url: '$ajax_url', data: { username: '{$model->username}', type: '{$type}', }, success: function (res) { if (res == 1) { clearInterval(window.timer); Dcat.swal.success('支付成功,请联系平台审核!', null, { onClose: function () { window.location.reload(); } }).then(() => { window.location.reload(); }); } } }); }, 1000); } }); JS; } return $js; } /** * 获取支付配置 * @param $model * @param $cost * @param $user_type * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string * @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException * @throws \GuzzleHttp\Exception\GuzzleException */ private function PayConfig($model, $cost, $user_type) { $setting = AdminSetting::val(['payee_appid', 'payee_mchid', 'payee_mchkey']); $config = [ 'app_id' => $setting['payee_appid'], 'mch_id' => $setting['payee_mchid'], 'key' => $setting['payee_mchkey'], 'notify_url' => route('wxpay_settled_notify'), ]; $app = Factory::payment($config); //生成订单号 list($micro, $sec) = explode(' ', microtime()); $micro = str_pad(floor($micro * 1000000), 6, 0, STR_PAD_LEFT); $order_no = date('ymdHis', $sec) . $micro . mt_rand(1000, 9999); //保存订单记录 SettledOrder::insertOrIgnore([ 'order_no' => $order_no, 'user_type' => $user_type, 'username' => $model->username, 'money' => $cost, 'status' => 0, 'created_at' => now(), 'updated_at' => now(), ]); return $app->order->unify([ 'product_id' => $model->id, 'attach' => $model->username, 'body' => mb_strcut($model->company_name . ' 入驻易游平台', 0, 127), 'out_trade_no' => $order_no, 'total_fee' => round($cost * 100), //支付金额单位为分 'trade_type' => 'NATIVE', // 请对应换成你的支付方式对应的值类型 ]); } }