调试支付代码:
public function test(Request $request){ $config = [ // 必要配置 'app_id' => '1111111111', 'mch_id' => '11111111111111', 'key' => '111111111111111', // API v2 密钥 (注意: 是v2密钥 是v2密钥 是v2密钥) // 如需使用敏感接口(如退款、发送红包等)需要配置 API 证书路径(登录商户平台下载 API 证书) 'cert_path' => '/pay_cert/apiclient_cert.pem', // XXX: 绝对路径!!!! 'key_path' => '/pay_cert/apiclient_key.pem', // XXX: 绝对路径!!!! 'notify_url' => 'xxxxx/open/wx/pay/callback', // 你也可以在下单时单独设置来想覆盖它 'total_fee' => 1, ]; $app = Factory::payment($config); $result = $app->order->unify([ 'out_trade_no' => 'kefu20240911'.rand(1,99999), 'trade_type' => 'JSAPI', 'total_fee' => 1, 'body' => '客服咨询支持', 'openid' => 'otzk36QMuBbysDM_e8geEY8eAsyw', // 'product_id' => $message['product_id'] ?? 123, // $message['product_id'] 则为生成二维码时的产品 ID // ... ]); Log::info(json_encode($result)); $params = (new \EasyWeChat\Payment\Jssdk\Client($app))->appConfig($result['prepay_id']); Log::info(json_encode($params)); $jssdk = $app->jssdk; $json = $jssdk->bridgeConfig($params["prepayid"]); Log::info($json); return view('pay.payOrder', [ "json"=>$json ]); }
[2024-09-18 16:43:18] prod.INFO: {"return_code":"SUCCESS","return_msg":"OK","result_code":"SUCCESS","mch_id":"xxxxx","appid":"xxxxx","nonce_str":"NuuNXHEAdX3uJSV7","sign":"xxx","prepay_id":"wx18164318345614ca1e7a181930972f0001","trade_type":"JSAPI"}
[2024-09-18 16:43:18] prod.INFO: {"appid":"xxxx","partnerid":"1685067562","prepayid":"xxxxx","noncestr":"66ea92a66b126","timestamp":1726648998,"package":"Sign=WXPay","sign":"EE0E0E0DEFFCA9EAB2A40B633048C8C5"}
[2024-09-18 16:43:18] prod.INFO: {"appId":"xxxx","timeStamp":"1726648998","nonceStr":"66ea92a66b2d7","package":"prepay_id=xxxx","signType":"MD5","paySign":"30ED49A75F6C7C96497DE2E5C59EA301"}
public function payCallback(Request $request){ Log::info("-------payCallback-------"); Log::info(json_encode($request->all())); $config = [ // 必要配置 'app_id' => '11111111111', 'mch_id' => '111111111', 'key' => '11111111111', // API v2 密钥 (注意: 是v2密钥 是v2密钥 是v2密钥) // 如需使用敏感接口(如退款、发送红包等)需要配置 API 证书路径(登录商户平台下载 API 证书) 'cert_path' => '/pay_cert/apiclient_cert.pem', // XXX: 绝对路径!!!! 'key_path' => '/pay_cert/apiclient_key.pem', // XXX: 绝对路径!!!! 'notify_url' => 'http://xxxxxx.com/open/wx/pay/callback', // 你也可以在下单时单独设置来想覆盖它 ]; $app = Factory::payment($config); $response = $app->handleScannedNotify(function ($message, $fail, $alert) use ($app) { Log::info(json_encode($message)); Log::info(json_encode($fail)); Log::info(json_encode($alert)); // 如:$alert('商品已售空'); // 如业务流程正常,则要调用“统一下单”接口,并返回 prepay_id 字符串,代码如下 $result = $app->order->unify([ 'out_trade_no' => 'kefu20240911'.rand(1,99999), 'trade_type' => 'NATIVE', 'total_fee' => 1, 'body' => '客服咨询支持', // 'product_id' => $message['product_id'] ?? 123, // $message['product_id'] 则为生成二维码时的产品 ID // ... ]); Log::info(json_encode($result)); return $result['prepay_id']; }); $response->send(); return "ok"; }
[2024-09-18 16:43:40] prod.INFO: -------payCallback-------
[2024-09-18 16:43:40] prod.INFO: {"_url":"\/open\/wx\/pay\/callback"}
[2024-09-18 16:43:40] prod.INFO: {"appid":"xxxxx","bank_type":"OTHERS","cash_fee":"1","fee_type":"CNY","is_subscribe":"N","mch_id":"xxxxx","nonce_str":"66ea92a612802","openid":"xxxx","out_trade_no":"xx","result_code":"SUCCESS","return_code":"SUCCESS","sign":"xx","time_end":"xx","total_fee":"1","trade_type":"JSAPI","transaction_id":"420000235668202409180830751151"}
[2024-09-18 16:43:40] prod.INFO: [{},"fail"]
[2024-09-18 16:43:40] prod.INFO: [{},"alert"]
[2024-09-18 16:43:40] prod.INFO: {"return_code":"SUCCESS","return_msg":"OK","result_code":"SUCCESS","mch_id":"xxxxxx","appid":"xxxxx","nonce_str":"Wipo7xHiPFWQiWwtoW","sign":"xx","prepay_id":"wx1816434022148617bdc8i6e4c6b737a0000","trade_type":"NATIVE","code_url":"weixin:\/\/wxpay\/bizpayurl?pr=sR3m82Mz1"}
打印日志:
本文来自博客园,作者:孙龙-程序员,转载请注明原文链接:https://www.cnblogs.com/sunlong88/p/18418840