基于ThinkPay的微信支付,摒弃腾讯自己搞的SDK,封装的太复杂了,直接基于ThinkPay一个文件实现微信支付,加群130747567。
基于ThinkPay的微信支付,摒弃腾讯自己搞的SDK,封装的太复杂了,直接基于ThinkPay一个文件实现微信支付,加群130747567。
/**<br>
* 微信支付驱动<br>
*/<br>
class Wxpay extends \Addons\Pay\ThinkPay\Pay\Pay {<br>
protected $gateway = 'https://api.mch.weixin.qq.com/pay/unifiedorder';<br>
protected $orderquery = 'https://api.mch.weixin.qq.com/pay/orderquery';<br>
protected $config = array(<br>
'appid' => '',<br>
'appsecret' => '',<br>
'mchid' => '',<br>
'key' => ''<br>
);<br>
<br>
public function check() {<br>
if (!$this->config['appid'] || !$this->config['appsecret'] || !$this->config['mchid'] || !$this->config['key']) {<br>
E("微信支付设置有误!");<br>
}<br>
return true;<br>
}<br>
<br>
public function buildRequestForm($pay_data) {<br>
// 获取用户openId,微信公众号JSAPI支付必须<br>
$openId = $this->GetOpenid();<br>
$param = array(<br>
'appid' => $this->config['appid'],<br>
'mch_id' => $this->config['mchid'],<br>
'nonce_str' => $this->getNonceStr(),<br>
'body' => $pay_data['body'],<br>
'out_trade_no' => $pay_data['out_trade_no'],<br>
'total_fee' => $pay_data['money'] * 100,<br>
'spbill_create_ip' => $_SERVER['REMOTE_ADDR'],<br>
'notify_url' => $this->config['notify_url'],<br>
'trade_type' => 'JSAPI',<br>
'openid' => $openId,<br>
);<br>
<br>
// 签名<br>
$param['sign'] = $this->MakeSign($param);<br>
$xml_param = $this->ToXml($param);<br>
$result = $this->FromXml($this->postXmlCurl($xml_param, $this->gateway));<br>
if($result['return_code'] === 'SUCCESS'){<br>
if ($this->CheckSign($result)) {<br>
$jsApiParameters = $this->GetJsApiParameters($result);<br>
$pay_page =
<br>
<br>
<meta>
<br>
<meta> <br>
<title>微信支付</title>
<br>
<script><br />
//调用微信JS api 支付<br />
function jsApiCall()<br />
{<br />
WeixinJSBridge.invoke(<br />
'getBrandWCPayRequest',<br />
{$jsApiParameters},<br />
function(res){<br />
WeixinJSBridge.log(res.err_msg);<br />
//alert(res.err_code+res.err_desc+res.err_msg);<br />
}<br />
);<br />
}<br />
<br />
function callpay()<br />
{<br />
if (typeof WeixinJSBridge == "undefined"){<br />
if( document.addEventListener ){<br />
document.addEventListener('WeixinJSBridgeReady', jsApiCall, false);<br />
}else if (document.attachEvent){<br />
document.attachEvent('WeixinJSBridgeReady', jsApiCall); <br />
document.attachEvent('onWeixinJSBridgeReady', jsApiCall);<br />
}<br />
}else{<br />
jsApiCall();<br />
}<br />
}<br />
</script><br>
<br>
<br>
<br><br>
<font><b>该笔订单支付金额为<span>{$pay_data['money']}</span>元</b></font><br><br><br>
<div>
<br>
<button>立即支付</button><br>
</div>
<br>
<br>
<br>
EOF;<br>
return $pay_page;<br>
}<br>
} else {<br>
E("微信订单错误!" . $result['return_msg']);<br>
}<br>
}<br>
}
AD:真正免费,域名+虚机+企业邮箱=0元
来源:php.cn
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
作者最新文章
-
2024-10-22 09:46:29
-
2024-10-13 13:53:41
-
2024-10-12 12:15:51
-
2024-10-11 22:47:31
-
2024-10-11 19:36:51
-
2024-10-11 15:50:41
-
2024-10-11 15:07:41
-
2024-10-11 14:21:21
-
2024-10-11 12:59:11
-
2024-10-11 12:17:31
最新问题
function_exists()无法判定自定义函数
function test() { return true; } if (function_exists('TEST')) { ech...
来自于 2024-04-29 11:01:01
0
2
1834
父窗口没有输出
document.onclick = function(){ window.opener.document.write('我是子窗口的输出'); ...
来自于 2024-04-18 23:52:34
0
1
1592
热门推荐
热门教程
更多>
-
-
php入门教程之一周学会PHP
4258693
-
JAVA 初级入门视频教程
2484407
-
小甲鱼零基础入门学习Python视频教程
504168
-
PHP 零基础入门教程
858805