Esempio n. 1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                WxConfig = EasyWeixin.CommonAPIs.CommonApi.GetWxConfigResult(appid, appsecert, Request.Url.ToString());
                QRCodeEncoder encoder = new QRCodeEncoder();
                Bitmap bt = encoder.Encode(Request.Url.ToString());

                var md5 = new MD5CryptoServiceProvider();
                var start = Encoding.Default.GetBytes(Request.Url.ToString());
                byte[] output = md5.ComputeHash(start);
                var result = BitConverter.ToString(output).Replace("-", "");

                var direName = "~/tmpQrImg/";
                var filename = direName + result + ".png";
                var filepath = Server.MapPath(filename);

                if (!Directory.Exists(direName))
                {
                    Directory.CreateDirectory(direName);
                }

                if (!File.Exists(filename))
                {
                    bt.Save(filename, ImageFormat.Png);
                }
                ImgSrc = filename;
            }
        }
Esempio n. 2
0
 protected void InitWeixinConfig()
 {
     WxConfigResult result = CommonApi.GetWxConfigResult(ActivityConfig.MHalloweenAppId,
         ActivityConfig.MHalloweenAppSecrect, Request.Url.ToString());
     WxConfig = result;
 }
Esempio n. 3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="appid"></param>
        /// <param name="secret"></param>
        /// <param name="url">要分享的url(从http开始,如果有参数,包含参数)</param>
        /// <returns></returns>
        public static WxConfigResult GetWxConfigResult(string appid, string secret, string url)
        {
            url = url.IndexOf("#", StringComparison.Ordinal) >= 0 ? url.Substring(0, url.IndexOf("#", StringComparison.Ordinal)) : url;

            var jsapiTicket = JsApiTicketContainer.TryGetTicket(appid, secret);
            var timestamp = CommonHelper.GetTimeStamp();
            var noncestr = CommonHelper.GuidTo16String(Guid.NewGuid());

            var str = string.Format("jsapi_ticket={0}&noncestr={1}&timestamp={2}&url={3}", jsapiTicket, noncestr, timestamp, url);

            var hash = CommonHelper.Sha1(str);

            var wxConfigResult = new WxConfigResult()
            {
                appid = appid,
                timestamp = timestamp,
                noncestr = noncestr,
                signature = hash,
                ticket = jsapiTicket,
                url = str
            };
            return wxConfigResult;
        }