微信H5支付 EasyWechat

1、公众号支付等资格申请

2、公众号对应的支付商户主体申请 开通H5支付

3、配置easywechat,并填写配置文件

4、方法中如下

public function userOrderWechatMobile(Request $request)
{
$data = $request->all();
//金钱特殊处理,通过后台查询取得
$res_order = \DB::table('dxjk_order')
->where('order_id',$data['order_id'])
->first();
$order_sid = $res_order->order_sid;
$money = $res_order->order_money;
$attributes = [
'trade_type' => 'MWEB', // JSAPI,NATIVE,APP...微信H5就是MWEB
'body' => '测试',
'detail' => '测试',
'out_trade_no' => $order_sid,
'total_fee' => $money * 100, // 单位:分
'notify_url' => 'https://jiankang.danxigu.com/dxjk/notifyUrlJk',
// 'openid' => $request->get('openid'),//小程序支付等需要
];
$orde = new Order($attributes);
// 统一下单
$result = $this->wechat->payment->prepare($orde);
$prepayId = null;
if ($result->return_code == 'SUCCESS' && $result->result_code == 'SUCCESS') {
$prepayId = $result->prepay_id;
// $config = $this->wechat->payment->configForPayment($prepayId,false);// 返回 json 字符串,如果想返回数组,传第二个参数 false
$config_jsp = $this->wechat->payment->configForJSSDKPayment($prepayId);//两种不同的返回
return ['code' => 1000, 'data' => $config_jsp];
} else {
return ['code' => 1001, 'data' => ['message' => '订单支付失败']];
}

}

猜你喜欢

转载自www.cnblogs.com/lvfish/p/9448945.html