예제 #1
0
        public static async Task <WeixinSession> GetSessionKey(string code)
        {
            if (string.IsNullOrEmpty(code))
            {
                return(null);
            }
            var    appId  = EnvironmentSetting.Get("appid");
            var    secret = EnvironmentSetting.Get("secret");
            string url    = $"https://api.weixin.qq.com/sns/jscode2session?appid={appId}&secret={secret}&js_code={code}&grant_type=authorization_code";

            using (var httpClient = new HttpClient())
            {
                using (var response = await httpClient.GetAsync(url))
                {
                    if (response.StatusCode != HttpStatusCode.OK)
                    {
                        return(null);
                    }
                    var body = await response.Content.ReadAsStringAsync();

                    var settings = new JsonSerializerSettings();
                    return(JsonConvert.DeserializeObject <WeixinSession>(body, settings));
                }
            }
        }
예제 #2
0
 public MysqlBase()
 {
     ConnectionString = EnvironmentSetting.Get("dbconnection");
 }