/// <summary> /// 获取微信配置信息 /// </summary> /// <returns></returns> public ActionResult GetWeChatConfig() { GetJsApiAccessTokenModel model = new GetJsApiAccessTokenModel(); model.sAppId = sAppId; model.sAppSecret = sAppSecret; IWeChatRequest request = new GetJsApiAccessTokenRequest(); var respone = request.Execute <GetJsApiAccessTokenRespone>(model); string noncestr = WeChatHelper.GetRandomStr(); long timestamp = WeChatHelper.GetTimeStamp(); string sign = ""; if (respone.errcode == 0) { string url = Request.UrlReferrer.AbsoluteUri; var paramters = new Dictionary <string, string>(); paramters.Add("jsapi_ticket", respone.ticket); paramters.Add("noncestr", noncestr); paramters.Add("timestamp", timestamp.ToString()); paramters.Add("url", url); sign = WeChatHelper.CreateSha1Sign(paramters); //返回的配置 paramters.Add("appId", sAppId); paramters.Add("signature", sign); result.success = true; result.data = paramters; } else { //公众号配置信息错误 result.info = "公众号配置信息错误"; result.success = false; } return(Content(JsonHelper.ToJsonString(result))); }
/// <summary> /// 执行获取调用JS接口的凭证的请求 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="model"></param> /// <returns></returns> public T Execute <T>(WeChatModel Model) { GetJsApiAccessTokenModel model = Model as GetJsApiAccessTokenModel; sRequestUrl = string.Format(sRequestUrl, model.sAccessToken); string result = HttpHelper.HttpGet(sRequestUrl); T Respone = JsonHelper.Deserialize <T>(result); return(Respone); }