PHP 微信统一下单API

	 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



  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值