微信accesstoken、ticket跨域服务器全局缓存(公共缓存)接口

广告:阿里云新人专场

微信的sdk文档要求接入方缓存两个参数:access_token和jsapi_ticket,在一定时间内这两个参数的值是不会过期的,不需要每次请求微信服务器获取。
参考以下文档获取access_token(有效期7200秒,开发者必须在自己的服务全局缓存access_token)
用第一步拿到的access_token采用http GET方式请求获得jsapi_ticket(有效期7200秒,开发者必须在自己的服务全局缓存jsapi_ticket):https://api.weixin.qq.com/cgi-bin/ticket/getticket?access_token=ACCESS_TOKEN&type=jsapi

<?xml version="1.0" encoding="utf-8"?>
<configuration>
<appSettings>
<add key="appId" value="" />
<add key="appSecret" value="" />
<add key="payApi" value="http://pay.53bk.com/" />
<add key="cacheApi" value="http://www.53bk.com/Api/WeixinCache" />
<add key="enableIP" value="127.0.0.1;127.0.0.1" />
</appSettings>
</configuration>

<!--http://www.53bk.com/Api/WeixinCache 微信accesstoken、ticket跨域服务器全局缓存(公共缓存)接口-->

全局缓存接口如:http://www.53bk.com/Api/WeixinCache

文章后台代码:

 #region WeixinCache() 服务器公共缓存接口 ---仅服务器端用 
 // /Api/WeixinCache?cachekey=accesstoken&hl=utf-8 /Api/WeixinCache?cachekey=ticket&hl=utf-8 
 public ActionResult WeixinCache() 
 { 
Response.Cache.SetOmitVaryStar(true);
 // Request.ContentEncoding = Encoding.GetEncoding("utf-8");
 string cachekey = "";
 if (Request.QueryString["cachekey"] != null)
 cachekey = Request.QueryString["cachekey"].ToString();
 if (Request.Form["cachekey"] != null)
 cachekey = Request.Form["cachekey"].ToString();
 string charset = "utf-8";
 if (Request.QueryString["hl"] != null)
 charset = Request.QueryString["hl"].ToString();
 if (Request.Form["hl"] != null)
 charset = Request.Form["hl"].ToString();
 if (charset == "utf-8")
 {
 Request.ContentEncoding = Encoding.GetEncoding("utf-8");
 Response.ContentEncoding = Encoding.GetEncoding("utf-8");
 }
 if (charset == "gb2312")
 {
 Request.ContentEncoding = Encoding.GetEncoding("gb2312");
 Response.ContentEncoding = Encoding.GetEncoding("gb2312");
 }
 if (charset == "gbk")
 {
 Request.ContentEncoding = Encoding.GetEncoding("gbk");
 Response.ContentEncoding = Encoding.GetEncoding("gbk");
 }
 string json1 = "";
 Weixinbll wxbll = new Weixinbll();
 if (cachekey=="accesstoken")
 {
 json1 = wxbll.getAccessTokenJsonstring();
 }
 if (cachekey == "ticket")
 {
 json1 = wxbll.getJsApiTicketJsonstring();
 }
 Response.Write(json1);
 return new EmptyResult();
 }
 #endregion 

最后程序后台形成接口post代码:

http://www.53bk.com/Api/WeixinCache?cachekey=accesstoken&hl=utf-8

广告:阿里云采购优惠专区

相关内容

编辑:Admin 时间:2021/11/2 9:30:29 阅览:33   返回    
accesstoken
微信
扫描关注53BK报刊官网
扫描关注阅速公司微信