一、微信公众号支付。
1.XXX/WechatPayController/getAuthorizeUrl?url=http://域名/项目/XXXController/toBuyCard,在controller方法里,获取url,重定向到
"https://open.weixin.qq.com/connect/oauth2/authorize"+"?"+"appid="+this.APPID+"&redirect_uri="+URLEncoder.encode(url,"UTF-8")+"&scope=snsapi_base";
2.在url中接收微信返回的code,利用code发送
"https://api.weixin.qq.com/sns/oauth2/access_token"+ "appid=" + APPID + "&" + "secret=" + secret + "&code=" + code+ "&grant_type=authorization_code"
获取openID;//返回的数据是json
3.将上面的openID发送到前台html页面,通过前台发送请求到后台,通过微信统一下单:参数
"nonce_str", "5K8264ILTKCH16CQ2502SI8ZNMTM67VS"
"body", "充值"
"out_trade_no", tradeNo
"fee_type", "CNY"
"total_fee", fee
"spbill_create_ip", clientIp
"notify_url", notifyUrl
"trade_type", "JSAPI"
"openid",openId
可以获取微信返回的JSON数据
4.将数据发送到前台html页面,通过jssdk,需要引入,拉起微信支付,
WeixinJSBridge.invoke('getBrandWCPayRequest',{
"appId" : appId, //公众号名称,由商户传入
"timeStamp" : timeStamp, //时间戳
"nonceStr" : nonceStr, //随机串
"package" : prepayIde,//扩展包
"signType" : "MD5",
"paySign" : signe //微信签名
},function(res){
alert("res"+JSON.stringify(res));
alert("res.err_msg"+res.err_msg);
if(res.err_msg == "get_brand_wcpay_request:ok") {
// window.location.href="toTransactionDetail.html?orderId="+$("#pay").attr("orderId");
window.location.href="XXX/XXXController/wxpayBuy"; //支付成功,去本地后台处理数据
}
});
注:1.APPID,secret,MchID,Key都需要微信公众号开通微信支付商户,然后部分参数配置
2.同时需要配置访问路径,只用到controller
二、微信公众号提现:
1.XXX/XXXController/getAuthorizeUrl?url=http://域名/项目/XXXController/authorizeCallback,获取code->openID,
2.通过openID 发送提现请求:参数
"mch_appid", appid
"mchid", mch_id
"nonce_str", new Date().getTime()+MyUtil.getStr(16)
"partner_trade_no", new Date().getTime()+""
"openid", openId
"check_name", "NO_CHECK"
"amount",""+ money*100
"desc", "提现"
"re_user_name", realName
"spbill_create_ip", spbill_create_ip//"192.168.1.1",
"sign", sign//通过上面的参数MD5生成
将参数组装成XML,发送到"https://api.mch.weixin.qq.com/mmpaymkttransfers/promotion/transfers"
返回的"return_code"和"result_code" 均为"SUCCESS"时为成功
注:这里提现,需要玩家的绑定微信号的真实姓名,需要安全证书,在微信商户平台下载