获取微信支付二维码链接时,调用接口提示 400

微信支付 文章 2022-01-18 15:20 1477 0 全屏看文

AI助手支持GPT4.0

获取微信支付二维码链接时,调用接口提示 400When getting the WeChat payment QR code link, the call interface prompts 400

获取微信支付二维码链接时,调用接口提示 400
提示错误:[400] ClientException in RequestException.php line 113Client error: `POST https://api.mch.weixin.qq.com/v3/pay/transactionsative` resulted in a `400 Bad Request` response一下是请求参数:$resp = $client->request(    'POST',    'https://api.mch.weixin.qq.com/v3/pay/transactionsative', //请求URL    [        // JSON请求体        'json' => [            "time_expire" => "2018-06-08T10:34:56+08:00",            "amount" => [   "total" => 100,   "currency" => "CNY",            ],            "mchid" => "1230000109",            "description" => "Image形象店-深圳腾大-QQ公仔",            "notify_url" => "https://www.weixin.qq.com/wxpay/pay.php",            "out_trade_no" => "1217752501201407033233368018",            "goods_tag" => "WXG",            "appid" => "wxd678efh567hg6787",            "attach" => "自定义数据说明",            "detail" => [   "invoice_id" => "wx123",   "goods_detail" => [       [           "goods_name" => "iPhoneX 256G",           "wechatpay_goods_id" => "1001",           "quantity" => 1,           "merchant_goods_id" => "商品编码",           "unit_price" => 828800,       ],       [           "goods_name" => "iPhoneX 256G",           "wechatpay_goods_id" => "1001",           "quantity" => 1,           "merchant_goods_id" => "商品编码",           "unit_price" => 828800,       ],   ],   "cost_price" => 608800,            ],            "scene_info" => [   "store_info" => [       "address" => "广东省深圳市南山区科技中一道10000号",       "area_code" => "440305",       "name" => "腾讯大厦分店",       "id" => "0001",   ],   "device_id" => "013467007045764",   "payer_client_ip" => "14.23.150.211",            ]        ],        'headers' => [ 'Accept' => 'application/json' ]    ]


提示错误:[400] ClientException in RequestException.php line 113Client error: `POST https://api.mch.weixin.qq.com/v3/pay/transactionsative` resulted in a `400 Bad Request` response一下是请求参数:$resp = $client->request( 'POST', 'https://api.mch.weixin.qq.com/v3/pay/transactionsative', //请求URL [ // JSON请求体 'json' => [ "time_expire" => "2018-06-08T10:34:56+08:00", "amount" => [ "total" => 100, "currency" => "CNY", ], "mchid" => "1230000109", "description" => "Image形象店-深圳腾大-QQ公仔", "notify_url" => "https://www.weixin.qq.com/wxpay/pay.php", "out_trade_no" => "1217752501201407033233368018", "goods_tag" => "WXG", "appid" => "wxd678efh567hg6787", "attach" => "自定义数据说明", "detail" => [ "invoice_id" => "wx123", "goods_detail" => [ [ "goods_name" => "iPhoneX 256G", "wechatpay_goods_id" => "1001", "quantity" => 1, "merchant_goods_id" => "商品编码", "unit_price" => 828800, ], [ "goods_name" => "iPhoneX 256G", "wechatpay_goods_id" => "1001", "quantity" => 1, "merchant_goods_id" => "商品编码", "unit_price" => 828800, ], ], "cost_price" => 608800, ], "scene_info" => [ "store_info" => [ "address" => "广东省深圳市南山区科技中一道10000号", "area_code" => "440305", "name" => "腾讯大厦分店", "id" => "0001", ], "device_id" => "013467007045764", "payer_client_ip" => "14.23.150.211", ] ], 'headers' => [ 'Accept' => 'application/json' ] ]

回答:

徐先生:

你的接口,是否真的正确?正常情况下,你把接口直接写在网页中,是有返回值的。我用的接口是:https://api.mch.weixin.qq.com/pay/unifiedorder

这个是我调用支付时用的接口,直接在网页中调用显示如下 :

使用你的接口(https://api.mch.weixin.qq.com/v3/pay/transactionsative)

显示如下:

宗明星:我也不清楚为什么接口时显示成那样,但接口地址就是那个啊。这是接口的地址:https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter3_4_1.shtml
徐先生:具体提示我不好说什么。但是,你提供的josn格式不对呀:你的格式是数组格式呀。json格式是{},如:
宗明星:这也是官方文档里面提供的方法,那你是怎么请求接口的?
徐先生:我们的用法不完全一样。我是JSAPI支付。贴出来部分代码,如果你觉得可能有用,我把文件发给你。


其中,http_request函数代码如下:

 //curl请求
 public function http_request($url,$data = null,$headers=array())
 {
  $curl = curl_init();
  if( count($headers) >= 1 ){
   curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
  }
  curl_setopt($curl, CURLOPT_URL, $url);
  curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
  curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);
  if (!empty($data)){
   curl_setopt($curl, CURLOPT_POST, 1);
   curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
  }
  curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
  $output = curl_exec($curl);
  curl_close($curl);
  return $output;
 }
徐先生:
徐先生:刚才的代码少了两行,重新发个图片。代码贴上去是乱码,只能用图片了。
星客微商城-900每年-xingke.vip:

我的是Java,我用Java 的时候直接传JSON对象也会报参数异常,需要传json字符串;试试把传递参数转为字符串,不要传类似map的对象。

Memory:

400是协议或者参数非法,自己根据文档查参数,可以用这个脚本辅助排查https://github.com/wechatpay-apiv3/wechatpay-postman-script

宗明星:我调用的就是官方文档里面的代码参数,没改过。地址:https://pay.weixin.qq.com/wiki/doc/apiv3/open/pay/chapter2_7_2.shtml的【3.2.1. 【服务端】Native下单】
宗明星:而且我尝试把参数去掉,发现去掉了之后也不行。

-EOF-

AI助手支持GPT4.0