WeChat custom sharing articles (senparc sdk version)

             

  1. The first step: front-end configuration wx.config,,,,,,
  2. Step 2: Configure the signature timestamp in the background and pass the appid to the foreground,,,,,, import sdk
  3.   Before generating a signature, you must first understand jsapi_ticket ( signature identification ). jsapi_ticket is a temporary ticket used by the official account to call the WeChat JS interface. Under normal circumstances, the validity period of jsapi_ticket is 7200 seconds , which can be obtained through access_token. Because the number of api calls to obtain jsapi_ticket is very limited, frequent refresh of jsapi_ticket will limit api calls and affect their own business. Developers must cache jsapi_ticket globally in their own services.

  4. The API to be called for the signature token (GET access): https://api.weixin.qq.com/cgi-bin/ticket/getticket?access_token=ACCESS_TOKEN&type=jsapi
  5. Fields involved in signature: noncestr (random string), valid jsapi_ticket, timestamp (timestamp), url (URL of the current web page, excluding # and its following parts ). After sorting all the parameters to be signed according to the ASCII code of the field name from small to large (lexicographical order), use the URL key-value pair format (ie key1=value1&key2=value2…) to concatenate them into a string string1. Note here that all parameter names are lowercase characters. Encrypt string1 with sha1, field name and word
  6. The segment values ​​are all raw, without URL escaping. Note: senparc has related methods to directly fill in the parameters, timestamps and random strings do not need to call the interface 
  7. /// <summary>
        /// Get WeChat JSSDK configuration data
        /// </summary>
        private void GetWxJsData()
        {
            if (ZhuiLangfun.GetWeixin() != 1)//ZhuiLang is my own method, don't be confused
            {
                try
                {
                    ZhuiLang_Wx ZhuiLang_Wx = new ZhuiLang_Wx();
                    noncestr = ZhuiLang_Wx.getNoncestr();
                    timestamp = ZhuiLang_Wx.getTimestamp();
                    string ticket = ZhuiLang_Wx.Get_WxJsSDK_Ticket();
                    string url = "jsapi_ticket=" + ticket + "&noncestr=" + noncestr + "×tamp=" + timestamp + "&url=http://" + ZhuiLangfun.GetHost() + Request.RawUrl;//Configure url url can be passed in the foreground or generated in the background
                    signature = SHA1Util.getSha1(url).ToLower();//This is the point//Get the signature
                    string[] WxJsArr = new string[4];
                    WxJsArr[0] = Example.Appid;
                    WxJsArr[1] = signature;
                    WxJsArr[2] = timestamp;
                    WxJsArr[3] = noncestr;
                    ViewState["WxJsArr"] = WxJsArr;
                }
                catch (Exception ee)
                {
                    //Response.Write(ee.ToString());
                }
            }
        }
  1. Step 3: Configure sharing parameters at the front desk,,,,,,,,,,,,,,,,,,,,


Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325587052&siteId=291194637