1.生成小程序二維碼功能
直接請求相應(yīng)的鏈接。傳遞相應(yīng)的參數(shù)
以生成商鋪的付款碼為例:
var shopsId = e.ShopsId
//付款碼的參數(shù)
var codeModel = new function () { }
codeModel.path = "pages/PageWxPay/PageWxPay?shopsId=" + shopsId
codeModel.width = 430
codeModel.auto_color = false
codeModel.line_color = { "r": "0", "g": "0", "b": "0" }
var data = {
shopsID: shopsId,
data: JSON.stringify(codeModel)
}
console.log(data)
api.RequestApiURL("Weixin/MyPaymentCode", data, function (codeData) {
console.log(codeData)
var obj = codeData.data.data
if (obj.Key == "0") {
that.setData({
payCodeUrl: app.globalData.apiurl + obj.Value
})
wx.hideLoading()
}
else {
wx.showToast({ title: obj.Value })
}
})
后臺代碼處理
private static object obj = new object();
///
/// 創(chuàng)建二維碼
/// 接口A: 適用于需要的碼數(shù)量較少的業(yè)務(wù)場景 接口地址:
/// 接口B:適用于需要的碼數(shù)量極多,或僅臨時使用的業(yè)務(wù)場景
/// 接口C:適用于需要的碼數(shù)量較少的業(yè)務(wù)場景
///
/// 前臺傳遞的數(shù)據(jù)
/// 圖片存儲位置
///
///
public static bool CreateWxaqrCode(Utils.QrCodeType nType, string data, string path, string toKen, out string ExcaptionMassage)
{
ExcaptionMassage = "";
bool msg = false;
string url = string.Empty;
switch (nType)
{
case Utils.QrCodeType.A:
url = "https://api.weixin.qq.com/wxa/getwxacode?access_token={0}";
break;
case Utils.QrCodeType.B:
url = "http://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token={0}";
break;
case Utils.QrCodeType.C:
url = "https://api.weixin.qq.com/cgi-bin/wxaapp/createwxaqrcode?access_token={0}";
break;
}
url = string.Format(url, toKen);
lock (obj)
{
//判斷當(dāng)前用戶是否生成二微碼
if (!System.IO.File.Exists(path))
{
try
{
//獲取數(shù)據(jù)流
Stream str = Request.PostMoths(url, data);
byte[] by = Utils.StreamToBytes(str);
Utils.PreservationCodeImage(path, by);
//保存該文件
msg = true;
}
catch(Exception e)
{
ExcaptionMassage= e.Message;
msg = false;//出現(xiàn)異常
}
}
}
return msg;
}
|