function HttpPost($url,$param){
$ch = curl_init();
//如果$param是数组的话直接用
curl_setopt($ch, CURLOPT_URL, $url);
//如果$param是json格式的数据,则打开下面这个注释
// curl_setopt($ch, CURLOPT_HTTPHEADER, array(
// 'Content-Type: application/json',
// 'Content-Length: ' . strlen($param))
// );
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $param);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
//如果用的协议是https则打开鞋面这个注释
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
$data = curl_exec($ch);
curl_close($ch);
return $data;
}
$appid = 'xxxxxxx';//你的appId
$attach = '支付测试';
$body = 'APP支付测试';
$mch_id = 'xxxxxx';//你的商户号
$nonce_str = '5K8264ILTKCH16CQ2502SI8ZNMTM67VS';//32位随机字符串(字母大写)
$notify_url = 'http://www.xxxx.com';//回调通知地址
$out_trade_no = '1415659990';//订单号
$spbill_create_ip = '14.23.150.211';//客户IP
$total_fee = '1';
$trade_type = 'APP';
$key = 'xxxxxxxxxxxxxxxxx';//你的key
//签名算法
$wechat_sign ="appid=$appid&attach=$attach&body=$body&mch_id=$mch_id&nonce_str=$nonce_str¬ify_url=$notify_url&out_trade_no=$out_trade_no&spbill_create_ip=$spbill_create_ip&total_fee=$total_fee&trade_type=$trade_type&key=$key";
$sign = strtoupper(MD5($wechat_sign));
$param ="<xml>
<appid>$appid</appid>
<attach>$attach</attach>
<body>$body</body>
<mch_id>$mch_id</mch_id>
<nonce_str>$nonce_str</nonce_str>
<notify_url>$notify_url</notify_url>
<out_trade_no>$out_trade_no</out_trade_no>
<spbill_create_ip>$spbill_create_ip</spbill_create_ip>
<total_fee>$total_fee</total_fee>
<trade_type>$trade_type</trade_type>
<sign>$sign</sign>
</xml>";
$url = "https://api.mch.weixin.qq.com/pay/unifiedorder";
var_dump(HttpPost($url,$param));
参数说明:https://pay.weixin.qq.com/wiki/doc/api/app/app.php?chapter=9_1