
h5响应式快速布局—微信小程序支付功能开发,小
[db:短标题]
责任撰写: zequninfo/
手机上手机微信手机微信微信小程序是进行现钱的最好专用型专用工具,进行功效进行手机微信微信小程序,如何手中机手机微信手机微信微信小程序开发设计设计方案中进行手机上手机微信支付功效?
,手机微信微信小程序进行功效
手机上手机微信手机微信微信小程序支付功效开发设计设计方案文字文本文档下列:
手机微信微信小程序端,储存大部分分分控制台版本号号
/* */
goWxPay: function () {
var that = this;
//登陆得到code
wx.login({
success: function (res) {
console.log( 得到login code ,res.code);
//得到openid
that.getOpenId(res.code);
}
});
},
/* 得到openId */
getOpenId: function (code) {
var that = this;
wx.request({
url: ****?code= + code, //互联网网络服务器端的乞求详尽详细地址,域名已加上手机微信微信小程序request受权管理方法
method: GET ,
success: function (res) {
console.log( 得到openid , res);
that.unitedPayRequest(res.data.openid);
},
fail: function () {
console.log( 得到openid 不了功 , res);
},
complete: function () {
console.log( 得到openid 完毕 , res);
}
});
},//getOpenId()
/*统一支付插孔*/
unitedPayRequest: function(openid){
var that=this;
//统一支付签名
var appid = //appid必填
var body = //商品名必填
var mch_id = //店家号必填
var nonce_str = util.randomString();//随意标志符串,没多久于32位。
var notify_url = //通知详尽详细地址必填
var total_fee = parseInt(0.01 * 100); //价格,它是一分钱
var trade_type = JSAPI
var key = //店家key必填,在店家后台管理管理方法获得
var out_trade_no = //自定订单号必填
var unifiedPayment = appid= + appid + body= + body + mch_id= + mch_id + nonce_str= + nonce_str + notify_url= + notify_url + openid= + openid + out_trade_no= + out_trade_no + total_fee= + total_fee + ™_type= + trade_type + key= + key;
console.log( unifiedPayment , unifiedPayment);
var sign = md5.md5(unifiedPayment).toUpperCase();
console.log( 签名md5 , sign);
//封裝统一支付xml关键主要参数
var formData = xml
formData += appid + appid + /appid
formData += body + body + /body
formData += mch_id + mch_id + /mch_id
formData += nonce_str + nonce_str + /nonce_str
formData += notify_url + notify_url + /notify_url
formData += openid + openid + /openid
formData += out_trade_no + that.data.ordernum + /out_trade_no
formData += total_fee + total_fee + /total_fee
formData += trade_type + trade_type + /trade_type
formData += sign + sign + /sign
formData += /xml
console.log( formData , formData);
//统一支付
wx.request({
url: api.mch.weixin.qq/pay/unifiedorder , //别忘了把api.mch.weixin.qq域名加上手机微信微信小程序request受权管理方法,这一目前可以加
method: POST ,
head: application/x-www-form-urlencoded ,
data: formData, //设置乞求的 header
success: function (res) {
console.log( 返回店家 , res.data);
var result_code = util.getXMLNodeValue( result_code , res.data.toString( utf-8 ));
var resultCode = result_code.split( [ )[2].split( ] )[0];
if (resultCode == FAIL ) {
var err_code_des = util.getXMLNodeValue( err_code_des , res.data.toString( utf-8 ));
var errDes = err_code_des.split( [ )[2].split( ] )[0];
wx.showToast({
title: errDes,
icon: none ,
duration: 3000
})
} else {
//开展支付
var prepay_id = util.getXMLNodeValue( prepay_id , res.data.toString( utf-8 ));
var tmp = prepay_id.split( [
var tmp1 = tmp[2].split( ]
//签名
var key = //店家key必填,在店家后台管理管理方法获得
var appId = //appid必填
var timeStamp = util.createTimeStamp();
var nonceStr = util.randomString();
var stringSignTemp = appId= + appId + nonceStr= + nonceStr + package=prepay_id= + tmp1[0] + signType=MD5 timeStamp= + timeStamp + key= + key;
console.log( 签名标志符串 , stringSignTemp);
var sign = md5.md5(stringSignTemp).toUpperCase();
console.log( 签名 , sign);
var param = { timeStamp : timeStamp, package : prepay_id= + tmp1[0], paySign : sign, signType : MD5 , nonceStr : nonceStr }
console.log( param手机微信微信小程序支付插孔关键主要参数 , param);
that.processPay(param);
}
},
})
},//unitedPayRequest()
/* 手机微信微信小程序支付 */
processPay: function (param) {
wx.requestPayment({
timeStamp: param.timeStamp,
nonceStr: param.nonceStr,
package: param.package,
signType: param.signType,
paySign: param.paySign,
success: function (res) {
// success
console.log( wx.requestPayment返回信息内容內容 ,res);
wx.showModal({
title: 支付获得取得成功 ,
content: 您将在“手机上手机微信支付”官方网网号中收到支付凭证 ,
showCancel: false,
success: function (res) {
if (res.confirm) {
} else if (res.cancel) {
}
}
})
},
fail: function () {
console.log( 支付不了功
},
complete: function () {
console.log( 支付开展(获得取得成功或不了功都为开展)
}
})
}//processPay()
许多个要选用的方法,除开MD5用从Github上找的编号,其他下列:
/* 时间戳导致涵数 */
function createTimeStamp() {
return parseInt(new Date().getTime() / 1000) +
}
/* 随意数 */
function randomString() {
var chars = ABCDEFGHJKMNPQRSTWXYZabcdefhijkmnprstwxyz2345678 //默认设置设定祛除了十分非常容易弄混的标志符oOLl,9gq,Vv,Uu,I1
var maxPos = chars.length;
var pwd =
for (var i = 0; i i++) {
pwd += chars.charAt(Math.floor(Math.random() * maxPos));
}
return pwd;
}
/* 得到XML联接点信息内容內容 */
function getXMLNodeValue(node_name, xml) {
var tmp = xml.split( + node_name + )
var _tmp = tmp[1].split( / + node_name + )
return _tmp[0]
}
module.exports = {
createTimeStamp: createTimeStamp,
randomString: randomString,
getXMLNodeValue: getXMLNodeValue
}
在服务端得到openid的PHP编号
//得到顾客openid
function getPortData($url){
$ch = curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, 0);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$r = curl_exec($ch);
//$r = json_decode($r);
if($error=curl_error($ch)){
die($error);
}
curl_close($ch);
return $r;
}
function getopenid(){
$code = $_GET[ code
if(empty($code)) return array( status = 0, info = 欠缺js_code
$appid = //必填
$appsecret = //必填
$url = api.weixin.qq/sns/jscode2session?appid= .$appid. secret= .$appsecret. js_code= .$code. grant_type=authorization_code
$result = getPortData($url);
//var_dump($result);
echo $result;
}
getopenid();
以上就是手机微信微信小程序进行的开发设计设计方案文字文本文档,很多文字文本文档可以关注。
[标识:內容1]
扫描二维码分享到微信