| 12
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 
 | //调起支付(仅示例扫码支付)$wechat_config = Config::get('wechat_pay');
 $config = [
 'app_id' => $wechat_config['app_id'],
 'mch_id' => $wechat_config['mch_id'],
 'key' => $wechat_config['key'],
 'notify_url' => 'https://'.$_SERVER['HTTP_HOST'].'/portal/Order/wechat_notify',
 'http' => [
 'timeout' => 5.0,
 'connect_timeout' => 5.0,
 ],
 ];
 $pay_order = [
 'out_trade_no' => $order['order_sn'],
 'total_fee' => $order['price']*100, //微信支付以分为单位
 'body' => '测试订单',
 ];
 try {
 //网站扫码支付
 $pay = Pay::wechat($config)->scan($pay_order);
 $qrcode = new Qrcode($pay->code_url);
 $image = $qrcode->getString();
 return response($image, 200, ['Content-Type' => 'image/jpeg']);
 } catch (\Exception $e) {
 echo $e->getMessage();
 }
 
 //回调验签(验签失败是会跑出异常的,最好写个捕获异常)
 $pay = Pay::wechat($config);
 $data = $pay->verify();
 $param = $data->all();
 //处理订单
 if ($param['result_code']=='SUCCESS'&&$param['return_code']=='SUCCESS') {
 (new OrderService($param['out_trade_no'], 'wechat'))->call_notice();
 }
 
 //退款(退款需要用到安全证书)
 $wechat_config = Config::get('wechat_pay');
 $config = [
 'app_id' => $wechat_config['app_id'],
 'mch_id' => $wechat_config['mch_id'],
 'key' => $wechat_config['key'],
 'cert_client' => $wechat_config['cert_client'],
 'cert_key' => $wechat_config['cert_key'],
 'http' => [
 'timeout' => 5.0,
 'connect_timeout' => 5.0,
 ],
 ];
 $wechat_order = [
 'out_trade_no' => $order['order_sn'],
 'out_refund_no' => $order['order_sn'],
 'total_fee' => $order['price']*100,
 'refund_fee' => $order['price']*100
 ];
 try {
 $pay = Pay::wechat($config)->refund($wechat_order);
 if ($pay->return_code != 'SUCCESS') {
 $this->error($pay->return_msg);
 }
 } catch (Exception $e) {
 $this->error($e->getMessage());
 }
 
 |