这两天闲着没事谢了一个微信支付的类,在统一下单卡住了,向统一下单提交的xml格式如下,(xml中的敏感内容已经替换掉了)
<xml>
<appid>appid</appid>
<mch_id>mch_id</mch_id>
<device_info>WEB</device_info>
<nonce_str>SDMMXJ4XG1KCPKT1AAYIOFPTWE5YCJJL</nonce_str>
<sign>ACDEB73B471195D9D0B9DDE5FD70ABDF</sign>
<sign_type>MD5</sign_type>
<body>JSAPI支付</body>
<detail><![CDATA[{"goods_detail":[{"goods_id": "12502", "wxpay_goods_id": "1001", "goods_name": "", "quantity": 1, "price": 528800}]}]]></detail>
<attach>商城</attach>
<out_trade_no>20200115110000000001</out_trade_no>
<fee_type>CNY</fee_type>
<total_fee>1</total_fee>
<spbill_create_ip>119.176.171.224</spbill_create_ip>
<time_start>1579074263</time_start>
<time_expire>1579074263</time_expire>
<notify_url>https://www.golaobao.com/wxpay/result.php</notify_url>
<trade_type>JSAPI</trade_type>
<openid>openid</openid>
</xml>
以上的xml数据使用curl向微信支付统一下单接口 https://api.mch.weixin.qq.com/pay/unifiedorder 提交数据后,接口没有返回数据。
以下是提交代码:
function postorder($orderXml){
$url="https://api.mch.weixin.qq.com/pay/unifiedorder";
$second=60;
$ch = curl_init();
$curlVersion = curl_version();
$ua = "WXPaySDK/3.0.9(".PHP_OS.") PHP/".PHP_VERSION." CURL/".$curlVersion[‘version‘]." ".MCHID;
//设置超时 ".self::$VERSION."
//die("出错");
curl_setopt($ch, CURLOPT_TIMEOUT, $second);
curl_setopt($ch,CURLOPT_URL, $url);
curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,false);
curl_setopt($ch,CURLOPT_SSL_VERIFYHOST,false);//严格校验
curl_setopt($ch,CURLOPT_USERAGENT, $ua);
//设置header
curl_setopt($ch, CURLOPT_HEADER, FALSE);
//要求结果为字符串且输出到屏幕上
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
$useCert=false;
if($useCert == true){
//设置证书
//使用证书:cert 与 key 分别属于两个.pem文件
//证书文件请放入服务器的非web目录下
$sslCertPath = "";
$sslKeyPath = "";
curl_setopt($ch,CURLOPT_SSLCERTTYPE,‘PEM‘);
curl_setopt($ch,CURLOPT_SSLCERT, $sslCertPath);
curl_setopt($ch,CURLOPT_SSLKEYTYPE,‘PEM‘);
curl_setopt($ch,CURLOPT_SSLKEY, $sslKeyPath);
}
//post提交方式
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS, $orderXml);
//运行curl
$data = curl_exec($ch);
curl_close($ch);
return $data;
//返回结果
}
但是执行之后,没有返回值,在网上查阅了很多的资料,都没有解决问题。