/// <summary> /// 获取js api ticket /// </summary> /// <returns>ticket</returns> public string GetJsApiTicket() { var token = cacheMgr.Get(JSAPI_TICKET__CACHE_KEY, 0, () => { var api = string.Format(JSAPI_TICKET_API, accessTokenSvc.GetToken()); var ticket = WxHelper.Send <JsApiTicket>(api, null, HttpMethod.Get); if (ticket != null) { if (cacheMgr.IsSet(JSAPI_TICKET__CACHE_KEY)) { cacheMgr.Remove(JSAPI_TICKET__CACHE_KEY); } string theTicket = ticket.ticket; cacheMgr.Set(JSAPI_TICKET__CACHE_KEY, theTicket, ticket.expires_in / 60); Log.Info(string.Format("获取JsApiTicket:{0}", theTicket)); return(ticket.ticket); } return(null); }); return(token); }
/// <summary> /// 发送模板消息 /// </summary> /// <param name="message">The message.</param> /// <returns></returns> public WxError SendTemplateMessage(WxTemplateMessage message) { string api = string.Format(TEMPLATE_MESSAGE_API, accessTokenSvc.GetToken()); var result = WxHelper.Send <WxError>(api, message); return(result); }
/// <summary> /// 创建二维码ticket, 临时二维码请求ticket /// </summary> public string GetQrCodeTicket(int sceneId) { const int expire = 10; var api = string.Format(TEMP_QR_CODE_TICKET_API, accessTokenSvc.GetToken()); var request = new QrCodeRequest() { expire_seconds = expire, action_name = "QR_SCENE", action_info = new QrCodeActionInfo() { scene = new Scene() { scene_id = sceneId } } }; var response = WxHelper.Send <QrCodeResponse>(api, request); if (response == null) { return(null); } #region 缓存场景id var key = string.Format(QR_CODE_SECENE, sceneId); if (cachMgr.IsSet(key)) { cachMgr.Remove(key); } cachMgr.Set(key, sceneId, expire); #endregion return(response.ticket); }
/// <summary> /// 发送消息 /// </summary> /// <param name="message">The message.</param> public WxError Send(CustomerMessage message) { var api = string.Format(SEND_API, accessTokenSvc.GetToken()); return(WxHelper.Send <WxError>(api, message)); }