示例#1
0
        /// <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("");
        }
示例#2
0
        /// <summary>
        /// 生成二维码图片到本地
        /// </summary>
        /// <param name="unionid"></param>
        /// <returns></returns>
        public string GetWxCodeToLocal(string unionid)
        {
            var wxcode = new WxCodeModel()
            {
                scene      = unionid,
                page       = "pages/index/index",
                width      = 430,
                auto_color = false,
                is_hyaline = false,
                // line_color = "{\"r\":\"0\",\"g\":\"0\",\"b\":\"0\"}"
            };
            var name         = System.Web.HttpContext.Current.Server.MapPath("/Content/UploadImg/" + unionid + ".jpg");
            var accountToken = "12_3XH0TwhYm2_WTx07yD0kHO-jNH3dirK3Ktj97H-FHQ7RANMBtZKgjFq8-kbgCeiIwaUg-3728Q6wFcGeYxtBBkPsvTs--7E3wM8ipDGtNV2K9TufeQpOxy3TTpPawFCYPr5kxphi_hCYusv3QCPgAFABNA";
            var istrue       = WebUtils.DoPostSaveImage("https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token=" + accountToken, JsonConvert.SerializeObject(wxcode), name);

            if (istrue)
            {
                return("http://localhost:62821/Content/UploadImg/" + unionid + ".jpg");
            }
            return("");
        }