PS:本文旨在简单获取prepay_id,只是简单的介绍一下流程,并非完整的订单支付流程
小程序端JS代码:
getxml(){
var test = this
wx.getStorage({
//从缓存中获取用户的openid
key:'openid',
success(res){
console.log(res)
test.setData({
'openid':res.data
})
console.log(test.data.openid)
}
})
wx.request({
url: 'http://', //你的URl地址
method:'POST',
header:{
'content-type':'application/x-www-form-urlencoded'
},
data:{
'openid':test.data.openid, //用户的opend
'description':'0.38mm.pen', //商品描述,此处为简单写了个例子,根据需要进行更改
'total':1 //商品总金额,单位为分,根据需求可以进行乘100
},
success(res){
console.log(res)
}
})
}
PS:这些JS代码通过点击按钮进行触发的,再次重申,本篇文章仅仅只是介绍获取prepay_id的流程,以及本人在写代码过程中遇到的一些问题
PHP代码:
API_connect.php
<?php
require_once dirname(__DIR__) .'/getCurl/curlDock.php';
class v2Connect
{
/**
* @param $URL :访问的API接口地址
* @param $data :通过POST传递的数据,xml格式
* @return bool|string :返回数据
*/
public function connect($URL,$data)
{
$this->action = curl_init();
curl_setopt($this->action, CURLOPT_URL, $URL);
curl_setopt($this->action, CURLOPT_HEADER, 0);
//curl_setopt($this->action, CURLOPT_HTTPHEADER, 0);
curl_setopt($this->action, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($this->action, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($this->action, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($this->action,