首页 技术 正文
技术 2022年11月15日
0 收藏 933 点赞 4,924 浏览 1696 个字

1.生成小程序二维码功能

直接请求相应的链接。传递相应的参数

以生成商铺的付款码为例:

.NET开发微信小程序-生成二维码 – 转

 var shopsId = e.ShopsId
//付款码的参数
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 })
}
})

.NET开发微信小程序-生成二维码 – 转

后台代码处理

.NET开发微信小程序-生成二维码 – 转

 private static object obj = new object();
/// <summary>
/// 创建二维码
/// 接口A: 适用于需要的码数量较少的业务场景 接口地址:
/// 接口B:适用于需要的码数量极多,或仅临时使用的业务场景
/// 接口C:适用于需要的码数量较少的业务场景
/// </summary>
/// <param name="data">前台传递的数据</param>
/// <param name="path">图片存储位置</param>
/// <param name="toKen"></param>
/// <returns></returns>
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)
{
//判断当前用户是否生成二微码
if (!System.IO.File.Exists(path))
{
try
{
//获取数据流
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;//出现异常
}
}
}
return msg;
}

.NET开发微信小程序-生成二维码 – 转

注:PostMoths方法在小程序基础配置里面有

StreamToBytes方法和PreservationCodeImage方法在支付里面有

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:8,996
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,510
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,353
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,137
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,770
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,848