|
//微信充值
Model.prototype.divWXClick = function(event){
var self_ = this;
if (!navigator.weixin) {
justep.Util.hint("尚未检测到"+name+"客户端,请使用其它方式充值!");
return;
}
var tradeNo =justep.UUID.createUUID(); //通常是交易流水号
var traceID =justep.UUID.createUUID();
var notifyUrl = location.origin + "/GetMoney";//支付成功通知地址
var totalFee=self_.comp("txtPrice").val();
if(totalFee==="")
{
justep.Util.hint("请填写充值金额。");
return;
}
totalFee=parseFloat(totalFee);//总金额(单位分)
if(isNaN(totalFee))
{
justep.Util.hint("充值金额格式不正确。");
return;
}
var reg = /^\+?[1-9][0-9]*$/;
if (!reg.test(totalFee))
{
justep.Util.hint("充值金额须大于0");
return;
}
var successCallback = function(prepayId) { //成功回调
//alert("prepayIdsuccess:"+prepayId);
justep.Baas.sendRequest({
"url" : "/GooHigh/GHIPower",
"action" : "inPrice",
"async" : false,
"params" : {
"prepayId":prepayId,
"uid":ghipower_logingUid,
"inPrice":totalFee,
"intype":"0"//微信充值
},
"success" : function(data) {
if(data!==null){
if(data.status===1)
{
justep.Util.hint("充值成功。");
self_.getParent().InitModel();
self_.close();
}
else
{
justep.Util.hint("后台处理失败,请与管理员联系。");
}
}
else
{
justep.Util.hint("返回值错误,data为空。");
}
}
});
};
var failCallback = function(prepayId) { //失败回调
//justep.Util.hint("微信充值失败,MSG="+prepayId);
justep.Util.hint("微信充值失败");
justep.Baas.sendRequest({
"url" : "/GooHigh/GHIPower",
"action" : "createLogs",
"async" : false,
"params" : {
"stype":"5",
"desc":"微信充值失败,MSG="+prepayId
},
"success" : function(data) {
}
});
};
var cancelCallback = function(prepayId) { //用户取消支付回调
//justep.Util.hint("微信充值被取消,payID="+prepayId);
justep.Util.hint("微信充值被取消");
justep.Baas.sendRequest({
"url" : "/GooHigh/GHIPower",
"action" : "createLogs",
"async" : false,
"params" : {
"stype":"3",
"desc":"微信充值被取消,payID="+prepayId
},
"success" : function(data) {
}
});
};
var weixin = navigator.weixin;
weixin.generatePrepayId({ // 生成预支付id
"body" : "测试",
"feeType" : "1",
"notifyUrl" : notifyUrl,
"totalFee" : totalFee*100,//总金额(单位分)
"traceId" : traceID,
"tradeNo" : tradeNo
}, function(prepayId) {
//alert("prepayId:"+prepayId);
weixin.sendPayReq(prepayId, function(message) { // 支付
var responseCode = parseInt(message);
//alert("message:"+message);
if (responseCode === 0) {
//支付成功
successCallback(prepayId);
}
if (responseCode === -1) {
//失败。
failCallback(prepayId);
}
if (responseCode === -2) {
//取消
cancelCallback(prepayId);
}
}, function(message) {
cancelCallback(prepayId);
});
}, function(message) {
//alert("messagefail:"+message);
failCallback(message);
});
};
|
|