企业微信应用,在调用企业微信接口时, 都需要用到 suite_ticket
suite_ticket:企业微信服务器会定时(每十分钟)推送ticket。ticket会实时变更
故: 在企业微信应用开发中, 首先需要先设计保存suite_ticket
在我的企业微信开发中, 企业微信指令回调URL中, 对suite_ticket 进行更新与保存
我这边的设计如下:
在数据库中, 添加微信数据的缓存表:
在此表中, 以应用的suite_id为主键, 保存了suite_access_token, suite_ticket两个值
在指令回调url中, 对suite_ticket进行更新, 代码如下:
[C#] 纯文本查看 复制代码 protected void Page_Load(object sender, EventArgs e)
{
//开启消息接受
if (Request.HttpMethod.ToUpper() == "GET")
{
......
}
else if (Request.HttpMethod.ToUpper() == "POST")
{
byte[] btHtml = Request.BinaryRead(Request.ContentLength);
string strHtml = System.Text.Encoding.Default.GetString(btHtml);
string signature = HttpContext.Current.Request.QueryString["msg_signature"];
string timestamp = HttpContext.Current.Request.QueryString["timestamp"];
string nonce = HttpContext.Current.Request.QueryString["nonce"];
string decryptEchoString = "";
WXBizMsgCrypt wxcpt = new WXBizMsgCrypt(WXConfig.sToken, WXConfig.sEncodingAESKey, WXConfig.sCorpID);
int ret = wxcpt.DecryptMsg(signature, timestamp, nonce, strHtml, ref decryptEchoString);
LogHelper.WriteLog("微信异步回调内容:" + decryptEchoString);
if (!string.IsNullOrEmpty(decryptEchoString))
{
try
{
var m_values = get_m_values(decryptEchoString);
//获取InfoType =action
string InfoType = InputHelper.GetInputString(m_values["InfoType"]);
switch (InfoType)
{
case "suite_ticket": // 微信推送suite_ticket
var suite_ticket = m_values["SuiteTicket"].ToString();
if (!string.IsNullOrEmpty(suite_ticket))
{
// 存储suite_ticket
var edit_result = cachebll.Update(DictBuilder.Assign("suite_ticket", suite_ticket).Assign("suite_ticket_update", DateTime.Now), $" suite_id='{WXConfig.SuiteID}'", null);
}
break;
}
}
catch (Exception ex)
{
//LogHelper.WriteLog("异步回调异常:" + ex.Message.ToString());
}
}
}
}
若开发者想立即获得ticket推送值,可登录服务平台,在第三方应用详情-回调配置,手动刷新ticket推送。 点此查看详情》》
|