示例#1
0
        /// <summary>
        /// singature签名的生成比较麻烦。
        /// 首先生成获取access_token
        /// (有效期7200秒,开发者必须在自己的服务全局缓存access_token)
        /// </summary>
        /// <returns></returns>
        public static string Getaccesstoken()
        {
            string         appid     = PayConfig.WxAppid();
            string         secret    = PayConfig.WxAppSecret();
            string         urljson   = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=" + appid + "&secret=" + secret;
            string         strjson   = "";
            UTF8Encoding   encoding  = new UTF8Encoding();
            HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(urljson);

            myRequest.Method      = "GET";
            myRequest.ContentType = "application/x-www-form-urlencoded";
            HttpWebResponse response;
            Stream          responseStream;
            StreamReader    reader;
            string          srcString;

            response       = myRequest.GetResponse() as HttpWebResponse;
            responseStream = response.GetResponseStream();
            reader         = new System.IO.StreamReader(responseStream, Encoding.UTF8);
            srcString      = reader.ReadToEnd();
            reader.Close();
            if (srcString.Contains("access_token"))
            {
                //CommonJsonModel model = new CommonJsonModel(srcString);
                CommonJsonModel model = new CommonJsonModel(srcString);
                strjson = model.GetValue("access_token");
                SessionTools.SetSession("access_tokenzj", strjson);
            }
            return(strjson);
        }
示例#2
0
 /// <summary>
 /// 模型是对象,key对应是集合,返回集合
 /// </summary>
 /// <param name="key"></param>
 /// <returns></returns>
 public CommonJsonModel GetCollection(string key)
 {
     if (!isModel)
     {
         return(null);
     }
     if (string.IsNullOrEmpty(key))
     {
         return(null);
     }
     foreach (string subjson in base._GetCollection(this.rawjson))
     {
         CommonJsonModel model = new CommonJsonModel(subjson);
         if (!model.IsValue())
         {
             continue;
         }
         if (model.Key == key)
         {
             CommonJsonModel submodel = new CommonJsonModel(model.Value);
             if (!submodel.IsCollection())
             {
                 return(null);
             }
             else
             {
                 return(submodel);
             }
         }
     }
     return(null);
 }
示例#3
0
        /// <summary>
        /// 当模型是对象,返回拥有的key
        /// </summary>
        /// <returns></returns>
        public List <string> GetKeys()
        {
            if (!isModel)
            {
                return(null);
            }
            List <string> list = new List <string>();

            foreach (string subjson in base._GetCollection(this.rawjson))
            {
                string key = new CommonJsonModel(subjson).Key;
                if (!string.IsNullOrEmpty(key))
                {
                    list.Add(key);
                }
            }
            return(list);
        }
示例#4
0
        /// <summary>
        /// 接着获取jsapi_ticket:
        /// 用第一步拿到的access_token 采用http GET方式请求获得jsapi_ticket
        /// (有效期7200秒,开发者必须在自己的服务全局缓存jsapi_ticket)
        /// </summary>
        /// <returns></returns>
        public static string Getjsapi_ticket()
        {
            string         accesstoken = (string)SessionTools.GetSession("access_tokenzj");
            string         urljson     = "https://api.weixin.qq.com/cgi-bin/ticket/getticket?access_token=" + accesstoken + "&type=jsapi";
            string         strjson     = "";
            UTF8Encoding   encoding    = new UTF8Encoding();
            HttpWebRequest myRequest   = (HttpWebRequest)WebRequest.Create(urljson);

            myRequest.Method      = "GET";
            myRequest.ContentType = "application/x-www-form-urlencoded";
            HttpWebResponse response       = myRequest.GetResponse() as HttpWebResponse;
            Stream          responseStream = response.GetResponseStream();
            StreamReader    reader         = new System.IO.StreamReader(responseStream, Encoding.UTF8);
            string          srcString      = reader.ReadToEnd();

            reader.Close();
            if (srcString.Contains("ticket"))
            {
                CommonJsonModel model = new CommonJsonModel(srcString);
                strjson = model.GetValue("ticket");
                SessionTools.SetSession("ticketzj", strjson);
            }
            return(strjson);
        }