基于ThinkPay的微信支付(JSAPI)
基于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元
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
-
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
Latest Issues
Team collaboration - What should I do if someone needs the feature I wrote as a dependency in git flow?
From 1970-01-01 08:00:00
0
0
0
Confusion about using gitlab's fork&pull request mode within the team
From 1970-01-01 08:00:00
0
0
0
Related Topics
More>
-
Usage of items in python
-
How to light up Douyin close friends moment
-
How to import data in access
-
Solution to java success and javac failure
-
What to do if temporary file rename fails
-
How to share a printer between two computers
-
C++ software Chinese change tutorial
-
What are the five types of aggregate functions?
Popular Recommendations
Popular Tutorials
More>
-
-
-
JAVA Beginner's Video Tutorial
2603851
-
-
Latest Downloads
More>
-
-
-
-
-
-
-
-