基于ThinkPay的微信支付(JSAPI)
- WBOY原創
- 2016-06-07 11:34:581084瀏覽
基于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元
陳述:本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn