欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  php教程

基于ThinkPay的微信支付(JSAPI)

程序员文章站 2022-05-17 21:00:42
...
基于ThinkPay的微信支付,摒弃腾讯自己搞的SDK,封装的太复杂了,直接基于ThinkPay一个文件实现微信支付,加群130747567。
基于ThinkPay的微信支付,摒弃腾讯自己搞的SDK,封装的太复杂了,直接基于ThinkPay一个文件实现微信支付,加群130747567。
基于ThinkPay的微信支付(JSAPI)
基于ThinkPay的微信支付(JSAPI)/**
* 微信支付驱动
*/
class Wxpay extends \Addons\Pay\ThinkPay\Pay\Pay {
protected $gateway = 'https://api.mch.weixin.qq.com/pay/unifiedorder';
protected $orderquery = 'https://api.mch.weixin.qq.com/pay/orderquery';
protected $config = array(
'appid' => '',
'appsecret' => '',
'mchid' => '',
'key' => ''
);

public function check() {
if (!$this->config['appid'] || !$this->config['appsecret'] || !$this->config['mchid'] || !$this->config['key']) {
E("微信支付设置有误!");
}
return true;
}

public function buildRequestForm($pay_data) {
// 获取用户openId,微信公众号JSAPI支付必须
$openId = $this->GetOpenid();
$param = array(
'appid' => $this->config['appid'],
'mch_id' => $this->config['mchid'],
'nonce_str' => $this->getNonceStr(),
'body' => $pay_data['body'],
'out_trade_no' => $pay_data['out_trade_no'],
'total_fee' => $pay_data['money'] * 100,
'spbill_create_ip' => $_SERVER['REMOTE_ADDR'],
'notify_url' => $this->config['notify_url'],
'trade_type' => 'JSAPI',
'openid' => $openId,
);

// 签名
$param['sign'] = $this->MakeSign($param);
$xml_param = $this->ToXml($param);
$result = $this->FromXml($this->postXmlCurl($xml_param, $this->gateway));
if($result['return_code'] === 'SUCCESS'){
if ($this->CheckSign($result)) {
$jsApiParameters = $this->GetJsApiParameters($result);
$pay_page =



微信支付





该笔订单支付金额为{$pay_data['money']}







EOF;
return $pay_page;
}
} else {
E("微信订单错误!" . $result['return_msg']);
}
}
}

AD:真正免费,域名+虚机+企业邮箱=0元