云托管的后端发起支付,得到错误
{"errcode":0,"errmsg":"ok","respdata":{"return_code":"FAIL","return_msg":"参数格式校验错误"}}
后端 php 代码如下(curl部分来自 TCloudBase/wxcloudrun-pay-demo )
public function directPay()
{
$url = 'http://api.weixin.qq.com/_/pay/unifiedOrder';
$hdr = Request::header();
$data = array(
"out_trade_no" => time(),
"body" => "测试支付",
"total_fee" => 50,
"openid" => $hdr["x-wx-openid"],
"env_id" => $hdr["x-wx-env"],
"spbill_create_ip" => $hdr["x-original-forwarded-for"],
"sub_mch_id" => "151195123",
"callback_type" => 2,
"container" => array(
"service" => $hdr["x-wx-service"],
"path" => "/api/payback",
)
);
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => $url,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_POSTFIELDS => json_encode($data),
CURLOPT_HTTPHEADER => array(
'Content-Type: application/json'
),
));
$response = curl_exec($curl);
curl_close($curl);
return $response;
}
很急!
商户号1开9位?
不要看示例json,对照着请求参数表每个参数不能少,参数类型也必须对
同问
补充:环境ID prod-4gb2q25m538957ce 2023-05-06 下午测试过几次