PHP函数
public function weixin_goods_pay() {
header ( 'Content-Type: text/html; charset=UTF-8' );
// $price = I ( 'price' );
// $post_price = I ( 'post_price' );
// $buyNum = I ( 'buyNum' );
$id = I ( 'id' );
$model = new WeixinGoodsModel ();
$goodArray = $model->get_info_byid ( $id );
$price = $goodArray ['price'];
$post_price = $goodArray ['post_price'];
$buyNum = I ( 'buyNum' );
$total_fee_title = $price * $buyNum + $post_price;
$this->assign ( 'total_fee_title', $total_fee_title );
$total_fee = $total_fee_title * 100;
$body = $goodArray ['title'];
$IncludePath = C ( 'IncludePath' );
require_once $IncludePath . 'weixin/pay/' . 'CommonUtil.php';
require_once $IncludePath . 'weixin/pay/' . 'WxPayHelper.php';
$options = array (
'APPID' => C ( 'weixin_api_AppId' ),
'APPSERCERT' => C ( 'weixin_api_AppSecret' ),
'APPKEY' => C ( 'weixin_api_pay_PaySignKey' ),
'SIGNTYPE' => 'sha1',
'PARTNERKEY' => C ( 'weixin_api_pay_partnerKey' )
);
$commonUtil = new \CommonUtil ();
$wxPayHelper = new \WxPayHelper ( $options );
$wxPayHelper->setParameter ( "bank_type", "WX" );
$wxPayHelper->setParameter ( "body", $body );
$wxPayHelper->setParameter ( "partner", C ( 'weixin_api_pay_partnerId' ) );
$wxPayHelper->setParameter ( "out_trade_no", $commonUtil->create_noncestr () );
$wxPayHelper->setParameter ( "total_fee", $total_fee );
$wxPayHelper->setParameter ( "fee_type", "1" );
$wxPayHelper->setParameter ( "notify_url", C ( 'weixin_api_url_paySeccess' ) );
$wxPayHelper->setParameter ( "spbill_create_ip", get_client_ip () );
$wxPayHelper->setParameter ( "input_charset", "UTF-8" );
$package = $wxPayHelper->create_biz_package ();
$this->assign ( 'package', $package );
// 显示模板
$this->display ( 'ApiPay:weixin_goods_pay' );
}
前台页面HTML
<include file="Public:public_header" />
<script language="javascript">
function callpay() {
WeixinJSBridge.invoke('getBrandWCPayRequest', {$package}, function(res) {
//WeixinJSBridge.log(res.err_msg);
//alert(res.err_code + res.err_desc + res.err_msg);
});
}
</script>
<div data-role="content" style="margin-top: 0px;">
<ul data-role="listview" data-inset="true">
<li data-role="list-divider" data-theme="f">
支付情况
</li>
<li data-icon="false" style="white-space:normal;">
您共需要支付{$total_fee_title}元!
</li>
</ul>
<a id="getBrandWCPayRequest" href="javascript:void(0);" onclick="callpay();" class="ui-btn ui-corner-all ui-btn-active">
我要支付
</a>
</div>
<include file="Public:public_footer_no" />
如下图
所用的支付接口类WxPayHelper.php,是基于微信官方提供的,但做了修改使之适合THINKPHP调用, 这儿我传不上来, 请移步到
http://www.abis.com.cn/thread-1175-1-1.html
下载支付接口压缩文件