全国服务热线:18980020603 成都热线:028-86633922
新闻中心网站专题联系我们
行业新闻 建站经验 网站建设资讯 手机网站资讯 微信网站建设资讯 APP开发资讯 商城网站资讯

微网站公众平台开发:怎么做微接入验证

发布人:桔子科技    发布时间:2015-01-05 09:54:49    分享到:
相要通过微和自身业务进行紧密相连,就需要实现如何与微服务器进行对接,涉足微开发,首先需要到微公众平台申请一个微公众号,打开开发者模式后,首先需要对您填写的url和Token进行验证,验证url的有效性,是微后续开发的首要条件。下面是实现url验证判断的代码:
  
       ///   
        /// 微URL验证  
        ///   
        private void RenZheng()
        {
            #region 新认证
            if (Request.HttpMethod.ToUpper() == "GET")
            {
                // 微加密签名    
                string signature = Request.QueryString["signature"];
                // 时间戳    
                string timestamp = Request.QueryString["timestamp"];
                // 随机数    
                string nonce = Request.QueryString["nonce"];
                // 随机字符串    
                string echostr = Request.QueryString["echostr"];
                if (CheckSignature(signature, timestamp, nonce))
                {
                    Response.Write(echostr);
                    Response.End();
                }
 
            }
            #endregion
        }
 
        public static bool CheckSignature(String signature, Stringtimestamp, String nonce)
        {
            string token = ViewUtil.WXToken;
            String[] arr = new String[] { token, timestamp, nonce };
            // 将token、timestamp、nonce三个参数进行字典序排序    
            Array.Sort(arr);
 
            StringBuilder content = new StringBuilder();
            for (int i = 0; i < arr.Length; i++)
            {
                content.Append(arr[i]);
            }
 
            String tmpStr = SHA1_Encrypt(content.ToString());
 
            // 将sha1加密后的字符串可与signature对比,标识该请求来源于微    
            return tmpStr != null ? tmpStr.Equals(signature) : false;
        }
 
        ///   
        /// 使用缺省密钥给字符串加密  
        ///   
        ///   
        ///   
        public static string SHA1_Encrypt(string Source_String)
        {
            byte[] StrRes = Encoding.Default.GetBytes(Source_String);
            HashAlgorithm iSHA = new SHA1CryptoServiceProvider();
            StrRes = iSHA.ComputeHash(StrRes);
            StringBuilder EnText = new StringBuilder();
            foreach (byte iByte in StrRes)
            {
                EnText.AppendFormat("{0:x2}", iByte);
            }
            return EnText.ToString();
        }
 
    }
 
 
验证成功后,即可成为开发者,可以根据自身业务实现各种个性话的功能定制,比如智能回复,多客服,消息自动推送,位置定位等,多样化的功能使得自身系统变得更加贴近实用,为用户带来实实在在的益处!
 

下一篇:建设微网站对企业有哪些好处呢?上一篇:微网站能给传统企业带来什么

最新案例
手机/微网站
  1. [成都]微信网站建设:微信分销系统能为商铺带来哪些特色服务
  2. [成都]微信网站建设:如何通过微信公众号来推广产品
  3. [成都]微信网站建设:微信开发都有些什么功能
  4. [成都]手机网站:手机网站设计需要达到什么效果
  5. [成都]手机网站:手机网站响应式网站解决方案
  6. [成都]手机网站:手机网站响应式网站解决方案
网络营销
  1. APP开发: APP网页评分功能设计
  2. APP开发:手机APP开发前这4点必须要了解
  3. APP开发:为什么企业要做手机APP
  4. APP开发:你可以更好的留住APP用户
  5. APP开发:开发时间的长短主要由哪些因素决定
  6. APP开发:电子商务类APP开发的4点建议
img

7x24小时售后服务

img

5倍故障时长赔付

img

15天无理由退款

img

N对一管家服务

让我们的顾问联系您

  • 电话:4006-028-024 028-86633922

    邮箱:Service@orangeapp.cn

    成都市成华区崔家店路789号上城国际1-24-9号

qq sina