/// <summary> /// 获取二维码使用b接口 /// </summary> /// <param name="appId"></param> /// <param name="path"></param> /// <param name="width"></param> /// <returns></returns> public static qrcodeclass GetWxQrcode(string access_token, string path, string scene, int width = 430) { qrcodeclass model = new qrcodeclass(); if (string.IsNullOrEmpty(path) || width <= 0) { model.isok = -1; model.msg = "参数错误"; return(model); } string postData = JsonConvert.SerializeObject(new { scene, page = path, width = 200, is_hyaline = false, }); string errorMessage = ""; string qrCode = HttpPostSaveImg("https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token=" + access_token, postData, ref errorMessage); if (string.IsNullOrEmpty(qrCode)) { model.isok = -1; model.msg = $"获取失败!{errorMessage}"; return(model); } model.url = qrCode; model.isok = 1; model.msg = "成功"; return(model); }
/// <summary> /// 获取小程序二维码 /// </summary> /// <param name="url">获取token的路径</param> /// <param name="AppId"></param> /// <returns></returns> public static qrcodeclass GetMiniAppQrcode_wxaapp(string access_token, string path, int width = 200) { qrcodeclass model = new qrcodeclass(); try { //小程序二维码 string qrCode = ""; string postData = JsonConvert.SerializeObject(new { path = path, width = width, }); string errorMessage = ""; qrCode = HttpPostSaveImg("https://api.weixin.qq.com/cgi-bin/wxaapp/createwxaqrcode?access_token=" + access_token, postData, ref errorMessage); if (string.IsNullOrEmpty(qrCode)) { model.isok = -1; model.msg = $"获取失败!{errorMessage}"; return(model); } model.url = qrCode; model.isok = 1; model.msg = "成功"; } catch (Exception) { } return(model); }
/// <summary> /// 获取小程序二维码 /// </summary> /// <param name="AppId"></param> /// <returns></returns> public static qrcodeclass GetMiniAppQrcode(string access_token, string page, string scene = "", int width = 200) { qrcodeclass model = new qrcodeclass(); try { string qrCode = ""; string errorMessage = ""; if (string.IsNullOrEmpty(scene)) { //表示新增 string postData = JsonConvert.SerializeObject(new { path = page, //page = page, width = width, auto_color = true, line_color = new { r = "0", g = "0", b = "0" } }); qrCode = HttpPostSaveImg("https://api.weixin.qq.com/wxa/getwxacode?access_token=" + access_token, postData, ref errorMessage); } else { //表示新增 string postData = JsonConvert.SerializeObject(new { scene = scene, page = page, //path = page, width = width, auto_color = true, line_color = new { r = "0", g = "0", b = "0" } }); qrCode = HttpPostSaveImg("https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token=" + access_token, postData, ref errorMessage); } if (string.IsNullOrEmpty(qrCode)) { model.isok = -1; model.msg = $"获取失败!{errorMessage}"; return(model); } model.url = qrCode; model.isok = 1; model.msg = "成功"; } catch (Exception ex) { model.msg = "异常" + ex.Message; } return(model); }
/// <summary> /// 获取小程序码不带参数 /// </summary> /// <param name="appId"></param> /// <param name="dmsg"></param> /// <param name="pagePath"></param> /// <returns></returns> public static string GetQrcode(string token, string pagePath, string scene = "") { string qrcodeImg = string.Empty; //获取二维码 qrcodeclass resultQcode = GetMiniAppQrcode(token, pagePath, scene); if (resultQcode != null) { if (resultQcode.isok > 0) { qrcodeImg = resultQcode.url; } } return(qrcodeImg); }