PS:本篇文章用于获取微信支付订单的查询,代码中使用的是out_trade_no:商户订单号来进行查询,可以直接将文中的out_trade_no替换为transaction_id微信支付订单号来进行查询,按照个人需求来就行,代码如下
小程序端js代码:
getData(){
wx.request({
url: 'http://127.0.0.1:2908/wxPayV2/queryOrder/actionQuery.php',
method:'GET',
header:{
'content_type':'application/json'
},
data:{
'out_trade_no':'此处写你的商户订单号' //如果写微信订单号记得将后面改为transaction_id
},
success(res){
console.log(res)
}
})
}
PHP相关的类的代码:
<?php
require_once ('../../config/appConfig.php');
class queryOrder{
public $appid;
public $mch_id;
public $APIv2;
/**
* 获取基本配置相关信息
*/
public function __construct(){
$appid = appid;
$mch_id = mchID;
$APIv2 = APIv2;
$this -> appid = $appid;
$this -> mch_id = $mch_id;
$this -> APIv2 = $APIv2;
}
/**
* @return string :返回32位随机字符串
*/
public function get_nonce_str(): string //此处可以写的更复杂些,为了篇幅我简单写一下
{
$body = '1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ';
$disposeData = str_shuffle($body);
return substr($disposeData,0