/// <summary> /// 获取Access_Token /// </summary> /// <param name="appId"></param> /// <param name="secret"></param> /// <returns></returns> public string GetAccessToken() { if (GetTimeStamp() - LastAccessToken > 7000) { string url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid={0}&secret={1}"; url = String.Format(url, appId, secret); string result = HttpGet(url); WxConfig config = JsonConvert.DeserializeObject <WxConfig>(result); AccessToken = config.access_token; LastAccessToken = GetTimeStamp(); } return(AccessToken); }
/// <summary> /// 获取Ticket /// </summary> /// <returns></returns> public string GetJsApiTicket() { if (GetTimeStamp() - LastJsApiTicket > 7000) { string accessToken = GetAccessToken(); string url = "https://api.weixin.qq.com/cgi-bin/ticket/getticket?access_token={0}&type=jsapi"; url = String.Format(url, accessToken); string result = HttpGet(url); WxConfig config = JsonConvert.DeserializeObject <WxConfig>(result); JsApiTicket = config.ticket; LastJsApiTicket = GetTimeStamp(); } return(JsApiTicket); }
/// <summary> /// 获取微信配置信息 /// </summary> /// <param name="url"></param> /// <returns></returns> public WxConfig GetShareConfig(string url) { string ticket = GetJsApiTicket(); string noncestr = GetNonceStr(); long timestamp = GetTimeStamp(); string signature = CreateSignature(ticket, noncestr, timestamp, url); WxConfig config = new WxConfig(); config.appId = appId; config.ticket = ticket; config.nonceStr = noncestr; config.timestamp = timestamp; config.signature = signature; return(config); }