统一下单接口:
<?php
namespace pay;
class WxPay
{
protected $appid;
protected $mch_id;
protected $key;
protected $openid;
protected $out_trade_no;
protected $body;
protected $total_fee;
function __construct($openid, $out_trade_no, $body, $total_fee,$notify_url)
{
$this->appid = '';//appid
$this->openid = $openid;//用户openid
$this->mch_id = '';//mch_id
$this->key = '';//key
$this->out_trade_no = $out_trade_no;//订单号
$this->body = $body;//订单描述
$this->total_fee = $total_fee;//金额(分)
$this->notify_url = $notify_url;//异步回调地址
}
public function pay()
{
//统一下单接口
$return = $this->weixinapp();
return $return;
}
//微信小程序接口
private function weixinapp()
{
//统一下单接口
$unifiedorder = $this->unifiedorder();
if(!$unifiedorder){
return false;
}
$parameters = array(
'appId' => $this->appid, //小程序ID
'timeStamp' => '' . time() . '', //时间戳
'nonceStr' => $this->createNoncestr(), //随机串
'package' => 'prepay_id=' . $unifiedorde