/// <summary> /// 设置备注名 /// </summary> /// <param name="OpenID"></param> /// <param name="Remark"></param> /// <returns></returns> public static int SetUserRemark(string OpenID, string Remark) { string Token = GetAccessTonken(); string URL = string.Format("https://api.weixin.qq.com/cgi-bin/user/info/updateremark?access_token={0}", Token); var postData = new { openid = OpenID, remark = Remark }; string postDataJson = Newtonsoft.Json.JsonConvert.SerializeObject(postData); string JsonResult = DataHelper.PostHttpData(URL, postDataJson); Dictionary <string, object> dic = JSONHelper.DataRowFromJSON(JsonResult); return(Function.ConverToInt(dic["errcode"].ToString())); }
private static string GetJsTicket() { if (!string.IsNullOrEmpty(JsTicket) && (DateTime.Now - TimeGetJsTicket).TotalHours < 1) { return(JsTicket); } string URL = string.Format(WeiXinConst.JsTicketURL, GetAccessTonken()); string Result = DataHelper.GetHttpData(URL); Dictionary <string, object> dic = JSONHelper.DataRowFromJSON(Result); if (dic.Keys.Contains("ticket")) { JsTicket = dic["ticket"].ToString(); TimeGetJsTicket = DateTime.Now; } return(JsTicket); }
private static string GetAccessTonkenHTTP(bool UpdateNew) { if (!string.IsNullOrEmpty(WeChat_tokenVal) && (DateTime.Now - TimeGetToken).TotalHours < 1) { return(WeChat_tokenVal); } string Result = DataHelper.GetHttpData(WeiXinConst.WeiXin_AccessTokenUrl); Dictionary <string, object> dic = JSONHelper.DataRowFromJSON(Result); if (dic.Keys.Contains("errcode")) { return(dic["errcode"].ToString()); } string TokenResult = dic["access_token"].ToString(); WeChat_tokenVal = TokenResult; TimeGetToken = DateTime.Now; return(TokenResult); }
/// <summary> /// Step2 根据Code获取AccessToken和OpenID /// </summary> /// <param name="WeChatCode"></param> /// <returns></returns> private Dictionary <string, object> GetAccessToken(string WeChatCode) { string tokenurl = UrlGetToken.Replace("((APPID))", WeiXinConst.AppId); tokenurl = tokenurl.Replace("((SECRET))", WeiXinConst.Secret); tokenurl = tokenurl.Replace("((CODE))", WeChatCode); string tokenResult = DataHelper.GetHttpData(tokenurl); Dictionary <string, object> TokenResultJson = JSONHelper.DataRowFromJSON(tokenResult); string js = string.Empty; if (TokenResultJson.Keys.Contains("errcode")) { return(null); } if (!TokenResultJson.Keys.Contains("access_token")) { return(null); } return(TokenResultJson); }