'测试商品', 'out_trade_no' => time(), 'total_fee' => '1', 'openid' => 'o38gpszoJoC9oJYz3UHHf6bEp0Lo', 'trade_type' => 'JSAPI', // JSAPI--JSAPI支付(服务号或小程序支付)、NATIVE--Native 支付、APP--APP支付,MWEB--H5支付 'notify_url' => 'https://a.com/text.html', 'spbill_create_ip' => '127.0.0.1', ]; // 生成预支付码 $result = $wechat->createOrder($options); echo '
';
    if ($options['trade_type'] === 'NATIVE') {
        echo '

二维码 NATIVE 支付,直接使用 code_url 生成二维码即可

'; var_export($result); return; } // 创建JSAPI参数签名 $options = $wechat->createParamsForJsApi($result['prepay_id']); echo "

--- 创建 JSAPI 预支付码 ---

"; var_export($result); // array( // 'return_code' => 'SUCCESS', // 'return_msg' => 'OK', // 'result_code' => 'SUCCESS', // 'mch_id' => '1332187001', // 'appid' => 'wx60a43dd8161666d4', // 'nonce_str' => 'YIPDbGWT1jpLLM5R', // 'sign' => '7EBBA1B5F196CF122C920D10FA768D96', // 'prepay_id' => 'wx211858080224615a10c2fc9f6c824f0000', // 'trade_type' => 'JSAPI', // ) echo "

--- 生成 JSAPI 及 H5 支付参数 ---

"; var_export($options); // array( // 'appId' => 'wx60a43dd8161666d4', // 'timeStamp' => '1669028299', // 'nonceStr' => '5s7h0dyp0nmzylbqytb462fpnb0tmrjg', // 'package' => 'prepay_id=wx21185819502283c23cca162e9d787f0000', // 'signType' => 'MD5', // 'paySign' => 'BBE0F426B8E1EEC9E45AC4459E8AE9D6', // 'timestamp' => '1669028299', // ) } catch (Exception $exception) { // 出错啦,处理下吧 echo $exception->getMessage() . PHP_EOL; }