微信小程序下单带调起支付 ——PHP(简易版本)
老板们觉着自己项目流量较大可以自行在生成订单时进行锁单
<?php
/**
* 公司名 小程序名
* @Descript: 订单模型
* @Filename: XcxOrder.php
* @Author: cjr
* @Date: 2019-8-21 14:16:44
* @Last Modified by: NULL
* @Last Modified time: NULL
*/
class Model_XcxOrder extends Model
{
public $response;
public $parameters;
public $url;//统一下单接口
public $curl_timeout;//curl超时时间
function __construct ()
{
//统一下单
$this->url = "https://api.mch.weixin.qq.com/pay/unifiedorder";
//设置curl超时时间
$this->curl_timeout = 30;
}
/**
* 生成签名
* @return array
*/
public function getXCXPreResult ()
{
$this->postXcxXml ();
$result = $this->xmlToArray ($this->response);
$arr = [
'appId' => $result['appid'] ,
'timeStamp' => (string) time () ,
'nonceStr' => $this->createNoncestr () ,//随机字符串
'package' => 'prepay_id=' . $result['prepay_id'] ,
'signType' => 'MD5'
];
$arr['paySign'] = $this->getXcxSign ($arr);//签名
return $arr;
}
/**
* 产生随机字符串,不长于32位
* @param $length int 随机长度
* @return string
*/
public function createNoncestr (