/// <summary> /// 查询数据库获得图文二进制 /// </summary> /// <param name="unionid"></param> /// <returns></returns> public byte[] WxCode(string unionid) { var _WeiXinCodeDao = new WeiXinCodeDao(); var code = _WeiXinCodeDao.GetByUnionid(unionid);//查找是否已经生成过 if (code != null) { return(code.ImageStream); } return(null); }
/// <summary> /// 生成二维码图片到数据库(保存二进制) /// </summary> /// <param name="unionid"></param> /// <returns></returns> public string GetWxCodeToData(string chanelid, string indirectchanel, string giftid, string unionid, int type = 0) { var scene = ""; if (type == 0) { scene = unionid; } if (type == 1) { unionid = chanelid + "_" + indirectchanel + "_" + giftid; scene = chanelid + "_" + indirectchanel + "_" + giftid; } var imgurl = "http://localhost:62821/XiaoApi/WxCodeIndex?unionid=" + unionid; var wxcode = new WxCodeModel() { scene = scene, page = "pages/index/index", width = 430, auto_color = false, is_hyaline = false, // line_color = "{\"r\":\"0\",\"g\":\"0\",\"b\":\"0\"}" }; var _WeiXinCodeDao = new WeiXinCodeDao(); var code = _WeiXinCodeDao.GetByUnionid(unionid);//查找是否已经生成过 if (code == null) { byte[] postdate; var accountToken = "16_lt7_qia0hGG3_h3hxN7VXhp6dmZ7gBQ4tBzA--mCacT3xkhjmXIOcKvglP-Wsr1B9YLzykfLc7sUCkmZhNEl4JHoq1RyZ1KOBY_PNycbaihq682qqHujIwT9pfz-ui3oZ67hrokyHWN9IT7mQALjAEAGQB"; var str = WebUtils.DoPostSaveImage("https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token=" + accountToken, JsonConvert.SerializeObject(wxcode), out postdate); var strtest = WebUtils.DoPost("https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token=" + accountToken, JsonConvert.SerializeObject(wxcode)); if (str) { var _WeiXinCode = new WeiXinCode() { CreateTime = DateTime.Now, ImageStream = postdate, UnionId = unionid, WxCodeUrl = "", }; _WeiXinCodeDao.Add(_WeiXinCode);//保存二进制流到数据库 code = _WeiXinCode; } } if (code != null) { return(imgurl); } return(""); }
public WeiXinCode GetByUnionid(string unionid) { return(_dao.GetByUnionid(unionid)); }