/// <summary> /// 获取公众号的AccessToken /// </summary> /// <returns>微信提供的AccessToken</returns> public string GetAccessToken() { logObj.Info("获取公众号的AccessToken,GetAccessToken()"); string accessToken = String.Empty; //先从数据库获取Access_Token,如果不存在或已过期,则重新跟微信拿Access_Token WeChatData wechatData = WeChatDataManage.SearchWeChatData("AccessToken"); if (wechatData != null) { logObj.Info("获取公众号的AccessToken,GetAccessToken(),数据库存在微信数据Key:AccessToken"); var wechatDataObj = JsonConvert.DeserializeObject <JObject>(wechatData.Value); var overdueTime = wechatData.UpdateTime.AddSeconds(int.Parse(wechatDataObj["expires_in"].ToString()));//access_token到期时间 if (DateTime.Now >= overdueTime) { logObj.Info("获取公众号的AccessToken,GetAccessToken(),数据库的微信数据Key:AccessToken已过期"); accessToken = GetWeixinAccessToken(); } else { logObj.Info("获取公众号的AccessToken,GetAccessToken(),等到有效的微信数据Key:AccessToken"); accessToken = wechatDataObj["access_token"].ToString(); } } else { logObj.Info("获取公众号的AccessToken,GetAccessToken(),数据库不存在微信数据Key:AccessToken,直接去微信获取AccessToken"); accessToken = GetWeixinAccessToken(); } logObj.Info("获取公众号的AccessToken,GetAccessToken(),返回:" + accessToken); return(accessToken); }
public string Handle(HttpRequestBase request) { var param = new WeChatData(request.QueryString); if (this.CheckSignature(param)) { if (!string.IsNullOrEmpty(param["echostr"])) { //首次验证 return param["echostr"]; } //触发处理数据之前事件 var data = new WeChatData(request.InputStream); //关于重试的消息排重 //微信服务器在五秒内收不到响应会断掉连接,并且重新发起请求,总共重试三次 if (!this.CheckIsFilter(data)) { this.OnStartHandle(data); return this.Excute(data); } else { return string.Empty; } } return string.Empty; }
/** * * 网页授权获取用户基本信息的全部过程 * 详情请参看网页授权获取用户基本信息:http://mp.weixin.qq.com/wiki/17/c0f37d5704f0b64713d5d2c37b468d75.html * 第一步:利用url跳转获取code * 第二步:利用code去获取openid和access_token * */ public void GetOpenidAndAccessToken() { if (!string.IsNullOrEmpty(currentHttpContext.Request.QueryString["code"])) { //获取code码,以获取openid和access_token string code = currentHttpContext.Request.QueryString["code"]; GetOpenidAndAccessTokenFromCode(code); } else { //构造网页授权获取code的URL string host = currentHttpContext.Request.Url.Host; string path = currentHttpContext.Request.Path; string redirect_uri = HttpUtility.UrlEncode("http://" + host + path); WeChatData data = new WeChatData(); data.SetValue("appid", WeChatConfig.APPID); data.SetValue("redirect_uri", redirect_uri); data.SetValue("response_type", "code"); data.SetValue("scope", "snsapi_base"); data.SetValue("state", state + "#wechat_redirect");//授权登录的改造 string url = "https://open.weixin.qq.com/connect/oauth2/authorize?" + data.ToUrl(); try { //触发微信返回code码 currentHttpContext.Response.Redirect(url);//Redirect函数会抛出ThreadAbortException异常,不用处理这个异常 } catch (System.Threading.ThreadAbortException ex) { } } }
/// <summary> /// 根据微信数据Id查找微信数据对象 /// </summary> /// <param name="id">微信数据Id</param> /// <returns>微信数据对象</returns> public WeChatData SearchWeChatData(Guid id) { log.InfoFormat("根据微信数据Id查找微信数据对象_SearchWeChatData(id:{0})", id); string sql = "SELECT Id,[Key],Value,UpdateTime FROM WeChatData WHERE Id=@id"; SqlParameter param = new SqlParameter("@id", id); SqlDataReader dataReader = null; WeChatData weChatData = null; try { dataReader = sqlHelper.ExecuteReader(sql, new SqlParameter[] { param }); if (dataReader.Read()) { log.Info("根据微信数据Id查找微信数据对象_SearchWeChatData(),读取到一条记录"); weChatData = new WeChatData() { Id = id, Key = dataReader["Key"].ToString(), Value = dataReader["Value"].ToString(), UpdateTime = Convert.ToDateTime(dataReader["UpdateTime"]) }; } } finally { if (dataReader != null) { dataReader.Close(); } } log.InfoFormat("根据微信数据Id查找微信数据对象_SearchWeChatData(),返回:weChatData.Value={0}", weChatData != null ? weChatData.Value : "null"); return(weChatData); }
/** * * 通过code换取网页授权access_token和openid的返回数据,正确时返回的JSON数据包如下: * { * "access_token":"ACCESS_TOKEN", * "expires_in":7200, * "refresh_token":"REFRESH_TOKEN", * "openid":"OPENID", * "scope":"SCOPE", * "unionid": "o6_bmasdasdsad6_2sgVt7hMZOPfL" * } * 其中access_token可用于获取共享收货地址 * openid是微信支付jsapi支付接口统一下单时必须的参数 * 更详细的说明请参考网页授权获取用户基本信息:http://mp.weixin.qq.com/wiki/17/c0f37d5704f0b64713d5d2c37b468d75.html * @失败时抛异常WxPayException */ public void GetOpenidAndAccessTokenFromCode(string code) { try { //构造获取openid及access_token的url WeChatData data = new WeChatData(); data.SetValue("appid", WeChatConfig.APPID); data.SetValue("secret", WeChatConfig.APPSECRET); data.SetValue("code", code); data.SetValue("grant_type", "authorization_code"); string url = "https://api.weixin.qq.com/sns/oauth2/access_token?" + data.ToUrl(); //请求url以获取数据 string result = HttpService.Get(url); //Log.Debug(this.GetType().ToString(), "GetOpenidAndAccessTokenFromCode response : " + result); WriteContent(result); //保存access_token,用于收货地址获取 JsonData jd = JsonMapper.ToObject(result); access_token = (string)jd["access_token"]; //获取用户openid openid = (string)jd["openid"]; } catch (Exception ex) { throw new WeChatException(ex.ToString()); } }
public string Excute(WeChatConfig config, WeChatData data) { //var msg = new //{ // button = new object[] // { // new {type="click",name="定位监控",key="CLICK_DWJK" }, // new {type="click",name="里程报表",key="CLICK_LCBB" }, // new // { // name="账号", // sub_button=new object[] // { // new {type="click",name="绑定账号",key="CLICK_BDZH" }, // new {type="click",name="取消绑定",key="CLICK_QXBD" } // } // } // } //}; var msg = new { button = new object[] { new { name="查车", sub_button=new object[] { new {type="click",name="定位监控",key="CLICK_DWJK" }, new {type="click",name="里程报表",key="CLICK_LCBB" } } }, new {type="click",name="设防撤防",key="CLICK_SFCF" }, new { name="账号", sub_button=new object[] { new {type="click",name="绑定账号",key="CLICK_BDZH" }, new {type="click",name="取消绑定",key="CLICK_QXBD" } } } } }; HttpHelper http = new HttpHelper(); HttpItem item = new HttpItem(); item.URL = string.Format("{0}menu/create?access_token={1}", config.APIUrl, config.AccessToken); item.Method = "POST"; item.Encoding = "utf-8"; item.ContentType = "application/x-www-form-urlencoded"; item.Postdata = msg.ToJsonString(); string result = http.GetHtml(item); return result; }
/// <summary> /// 获取AccessToken /// </summary> private void GetAccessToken() { HttpHelper http = new HttpHelper(); HttpItem item = new HttpItem(); item.URL = string.Format("{0}token?grant_type=client_credential&appid={1}&secret={2}", config.APIUrl, config.AppID, config.AppSecret); string json = http.GetHtml(item); var data = new WeChatData(json); config.AccessToken = data["access_token"]; config.ExpiresIn = DateTime.Now.AddSeconds(data.Get<int>("expires_in")); }
/// <summary> /// 响应消息 /// </summary> /// <returns></returns> public static string Excute(WeChatConfig config, WeChatData data) { if (!data.MsgType.HasValue()) return string.Empty; var cmd = GetCMD(data.MsgType); if (cmd != null) { return cmd.Excute(config, data); } return string.Empty; }
/// <summary> /// 在请求之前执行 /// </summary> private void OnStartHandle(WeChatData data) { //检查AccessToken是否已经过去 this.CheckExpires(); //var getMenuCMDResult = new GetMenuCMD().Excute(config, data).ToWeChatData(); //if (getMenuCMDResult.Get<int>("errcode") == 46003) //{ // //如果菜单不存在 那么创建菜单 // var result = new CreateMenuCMD().Excute(config, data).ToWeChatData(); //} }
/// <summary> /// 添加或更新微信数据记录,不存在同Key则添加,存在则更新 /// </summary> /// <param name="weChatData">微信数据对象</param> /// <returns>是否新增或更新成功</returns> public bool InsertOrUpdateWeChatData(WeChatData weChatData) { try { new LogHelper(this.GetType()).InfoFormat("添加或更新微信数据记录InsertOrUpdateWeChatData(weChatData.Key:{0},weChatData.Value:{1})", weChatData.Key, weChatData.Value); weChatData.UpdateTime = DateTime.Now; return(WeChatDataService.InsertOrUpdateWeChatData(weChatData)); } catch (Exception ex) { new LogHelper(this.GetType()).Error("添加或更新微信数据记录InsertOrUpdateWeChatData(),发生异常", ex); return(false); } }
public void GetUserInfo() { if (!string.IsNullOrEmpty(currentHttpContext.Request.QueryString["code"])) { //获取code码,以获取openid和access_token string code = currentHttpContext.Request.QueryString["code"]; GetOpenidAndAccessTokenFromCode(code); //拉取用户基本信息 string user_info_api = "https://api.weixin.qq.com/sns/userinfo?access_token=" + this.access_token + "&openid=" + openid + "&lang=zh_CN"; string result = HttpService.Get(user_info_api); WriteContent(result); JsonData jd = JsonMapper.ToObject(result); nickname = (string)jd["nickname"]; sex = (int)jd["sex"]; province = (string)jd["province"]; city = (string)jd["city"]; country = (string)jd["country"]; headimgurl = (string)jd["headimgurl"]; //unionid = (string)jd["unionid"]; } else { //构造网页授权获取code的URL string host = currentHttpContext.Request.Url.Host; string path = currentHttpContext.Request.Path; string redirect_uri = HttpUtility.UrlEncode("http://" + host + path); WeChatData data = new WeChatData(); data.SetValue("appid", WeChatConfig.APPID); data.SetValue("redirect_uri", redirect_uri); data.SetValue("response_type", "code"); data.SetValue("scope", "snsapi_userinfo"); data.SetValue("state", state + "#wechat_redirect");//授权登录的改造 string url = "https://open.weixin.qq.com/connect/oauth2/authorize?" + data.ToUrl(); try { //触发微信返回code码 currentHttpContext.Response.Redirect(url);//Redirect函数会抛出ThreadAbortException异常,不用处理这个异常 } catch (System.Threading.ThreadAbortException ex) { } } }
/// <summary> /// 根据Id或Key更新微信数据记录 /// </summary> /// <param name="weChatData">微信数据对象</param> /// <returns>是否更新成功</returns> public bool UpdateWeChatData(WeChatData weChatData) { log.Info("根据Id或Key更新微信数据记录,UpdateWeChatData()"); string sql = "UPDATE WeChatData SET Value=@value,UpdateTime=@updateTime WHERE Id=@id OR [Key]=@key"; SqlParameter[] param = new SqlParameter[] { new SqlParameter("@value", weChatData.Value), new SqlParameter("@updateTime", weChatData.UpdateTime), new SqlParameter("@id", weChatData.Id), new SqlParameter("@key", weChatData.Key) }; bool result = sqlHelper.ExecuteNonQuery(sql, param) > 0; log.Info("根据Id或Key更新微信数据记录,UpdateWeChatData(),返回:" + result); return(result); }
/// <summary> /// 新增一条微信数据记录 /// </summary> /// <param name="weChatData">微信数据对象</param> /// <returns>是否新增成功</returns> public bool InsertWeChatData(WeChatData weChatData) { log.InfoFormat("新增一条微信数据记录InsertWeChatData((weChatData.Key:{0},weChatData.Value:{1})", weChatData.Key, weChatData.Value); string sql = "INSERT INTO WeChatData(Id,[Key],Value,UpdateTime) VALUES(@Id,@key,@value,@updateTime)"; SqlParameter[] paras = new SqlParameter[] { new SqlParameter("@Id", Guid.NewGuid()), new SqlParameter("@key", weChatData.Key), new SqlParameter("@value", weChatData.Value), new SqlParameter("@updateTime", weChatData.UpdateTime) }; int row = sqlHelper.ExecuteNonQuery(sql, paras); log.InfoFormat("新增一条微信数据记录InsertWeChatData(),影响行数:", row); return(row > 0); }
/// <summary> /// 添加或更新微信数据记录,不存在同Key则添加,存在则更新 /// </summary> /// <param name="weChatData">微信数据对象</param> /// <returns>是否新增或更新成功</returns> public bool InsertOrUpdateWeChatData(WeChatData weChatData) { log.InfoFormat("添加或更新微信数据记录InsertOrUpdateWeChatData(weChatData.Key:{0},weChatData.Value:{1})", weChatData.Key, weChatData.Value); WeChatData wechatData = SearchWeChatData(weChatData.Key); if (weChatData == null) { log.InfoFormat("添加或更新微信数据记录InsertOrUpdateWeChatData(),不存在Key:{0},添加记录", weChatData.Key); return(InsertWeChatData(weChatData)); } else { log.InfoFormat("添加或更新微信数据记录InsertOrUpdateWeChatData(),存在Key:{0},更新记录", weChatData.Key); return(UpdateWeChatData(weChatData)); } }
/// <summary> /// 根据微信数据的Key查找微信数据对象 /// </summary> /// <param name="id">微信数据的Key</param> /// <returns>微信数据对象</returns> public WeChatData SearchWeChatData(string key) { log.InfoFormat("根据微信数据的Key查找微信数据对象_SearchWeChatData(key:{0})", key); string sql = "SELECT Id,[Key],Value,UpdateTime FROM WeChatData WHERE [Key]=@key"; SqlParameter param = new SqlParameter("@key", key); SqlDataReader dataReader = sqlHelper.ExecuteReader(sql, new SqlParameter[] { param }); WeChatData weChatData = null; if (dataReader.Read()) { log.Info("根据微信数据的Key查找微信数据对象_SearchWeChatData(),读取到一条数据"); weChatData = new WeChatData() { Id = Guid.Parse(Convert.ToInt32(dataReader["Id"]).ToString()), Key = dataReader["Key"].ToString(), Value = dataReader["Value"].ToString(), UpdateTime = Convert.ToDateTime(dataReader["UpdateTime"]) }; } dataReader.Close(); log.InfoFormat("根据微信数据的Key查找微信数据对象_SearchWeChatData(),返回:weChatData.Id={0}", (weChatData != null ? weChatData.Id.ToString() : "null")); return(weChatData); }
/// <summary> /// 定位监控 /// </summary> /// <param name="data"></param> /// <returns></returns> private string ClickDWJK(WeChatData data) { if (!CheckIsBind(data.FromUserName)) { return data.ToQuicklyReplayWeChatData("您还没有绑定平台账号!"); } else { var userId = GetUserIdByWeChatUserName(data.FromUserName); if (userId == 0) { return data.ToQuicklyReplayWeChatData("您还没有绑定平台账号!"); } var devices = _rep.GetList<EDevice>(8, p => p.UserId == userId); if (devices.Count == 0) { return data.ToQuicklyReplayWeChatData("您还没有添加车辆!"); } var list = devices.Select(p => new WeChatItemData() { Title = p.DeviceName, Url = string.Format("{0}WeChat/CurrentData?deviceId={1}&weChatUserName={2}", _config.Host, p.Id, data.FromUserName) }).ToList(); list.Insert(0, new WeChatItemData() { Title = "查看车辆位置", Url = "#", PicUrl = string.Format("{0}Areas/Gps/Content/Images/WeChat/position.png", _config.Host) }); return data.ToNewsWeChatData(list); } }
/// <summary> /// 事件入口 /// </summary> /// <param name="data"></param> /// <returns></returns> private string ExcuteEvent(WeChatData data) { if (!data.Event.HasValue()) return string.Empty; switch (data.Event) { case "subscribe": //关注事件 return data.ToQuicklyReplayWeChatData("您已经成功关注!"); case "unsubscribe": //取消关注事件 break; case "SCAN": //扫描带参数二维码事件 return data.ToQuicklyReplayWeChatData("您已经成功关注!"); case "LOCATION": //上报地理位置事件 break; case "VIEW": //点击菜单跳转链接时的事件推送 break; case "CLICK": //点击菜单拉取消息时的事件推送 if (data.EventKey.HasValue()) { switch (data.EventKey.Replace("_", "")) { case "ClickBDZH": return this.ClickBDZH(data); case "ClickQXBD": return this.ClickQXBD(data); case "ClickDWJK": return this.ClickDWJK(data); } } break; default: break; } return string.Empty; }
/// <summary> /// 验证请求 /// </summary> /// <returns></returns> private bool CheckSignature(WeChatData data) { string[] array = { _config.Token, data["timestamp"], data["nonce"] }; Array.Sort(array); return data["signature"].Equals(FormsAuthentication.HashPasswordForStoringInConfigFile(string.Join("", array), "SHA1").ToLower()); }
/// <summary> /// 检查是否过滤消息 /// </summary> /// <param name="data"></param> /// <returns></returns> private bool CheckIsFilter(WeChatData data) { lock (_o) { if (data.MsgId.HasValue()) { //消息 使用msgid排重 if (_msgs.Contains(data.MsgId)) { return true; } else { if (_msgs.Count > 1000) { _msgs.Clear(); } _msgs.Add(data.MsgId); return false; } } else { //事件 使用FromUserName + CreateTime 排重 if (_msgs.Contains(data.FromUserName + data.CreateTime)) { return true; } else { if (_msgs.Count > 1000) { _msgs.Clear(); } _msgs.Add(data.FromUserName + data.CreateTime); return false; } } } }
private void GetAccessToken() { HttpLibSyncRequestItem item = new HttpLibSyncRequestItem(); item.Url = string.Format("{0}token?grant_type=client_credential&appid={1}&secret={2}", _config.ApiUrl, _config.AppId, _config.AppSecret); string json = HttpLibSyncRequest.Get(item); var data = new WeChatData(json); _config.AccessToken = data["access_token"]; _config.ExpiresIn = DateTime.Now.AddSeconds(data.Get<int>("expires_in")); }
public string Excute(WeChatConfig config, WeChatData data) { if (!data.Event.HasValue()) return string.Empty; switch (data.Event) { case "subscribe": //关注事件 return data.ToQuicklyReplayWeChatData("您已经成功关注魔方(MOVO)平台!"); case "unsubscribe": //取消关注事件 ModelFacade.WeChat.WeChatModel.UnBind(data.FromUserName); break; case "SCAN": //扫描带参数二维码事件 return data.ToQuicklyReplayWeChatData("您已经成功关注魔方(MOVO)平台!"); case "LOCATION": //上报地理位置事件 break; case "VIEW": //点击菜单跳转链接时的事件推送 break; case "CLICK": //点击菜单拉取消息时的事件推送 if (data.EventKey.HasValue()) { var cmd = CMDManage.GetCMD("On" + data.EventKey.Replace("_", "")); if (cmd != null) { return cmd.Excute(config, data); } else { return string.Empty; } } break; default: break; } return string.Empty; }
/// <summary> /// 请求微信用户公开的信息 /// </summary> /// <param name="appid">应用id</param> /// <param name="secret">应用秘密指令</param> /// <param name="code">微信客户端返回的code</param> /// <returns></returns> IEnumerator GetWeChatUserData(string appid, string secret, string code) { //第一步:通过appid、secret、code去获取请求令牌以及openid; //code是用户在微信登录界面授权后返回的 string url = "https://api.weixin.qq.com/sns/oauth2/access_token?appid=" + appid + "&secret=" + secret + "&code=" + code + "&grant_type=authorization_code"; UnityWebRequest www = UnityWebRequest.Get(url); yield return(www.SendWebRequest()); if (www.error != null) { Debug.Log("微信登录请求令牌失败:" + www.error); } else { Debug.Log("微信登录请求令牌成功:" + www.downloadHandler.text); WeChatData weChatData = JsonUtility.FromJson <WeChatData>(www.downloadHandler.text); if (weChatData == null) { yield break; } else { //第二步:请求个人微信公开的信息 string getuserurl = "https://api.weixin.qq.com/sns/userinfo?access_token=" + weChatData.access_token + "&openid=" + weChatData.openid; UnityWebRequest getuser = UnityWebRequest.Get(getuserurl); yield return(getuser.SendWebRequest()); if (getuser.error != null) { Debug.Log("向微信请求用户公开的信息,出现异常:" + getuser.error); } else { //从json格式的数据中反序列化获取 WeChatUserData weChatUserData = JsonUtility.FromJson <WeChatUserData>(getuser.downloadHandler.text); if (weChatUserData == null) { Debug.Log("error:" + "用户信息反序列化异常"); yield break; } else { Debug.Log("用户信息获取成功:" + getuser.downloadHandler.text); Debug.Log("openid:" + weChatUserData.openid + ";nickname:" + weChatUserData.nickname); //获取到微信的openid与昵称 string wxOpenID = weChatUserData.openid; string wxNickname = weChatUserData.nickname; int sex = weChatUserData.sex;//1为男性,2为女性 //微信登录 外部要处理的事件 weChatLogonCallback(weChatUserData); } } } } }
public string Excute(WeChatConfig config, WeChatData data) { if (!ModelFacade.WeChat.WeChatModel.CheckIsBind(data.FromUserName)) { return data.ToQuicklyReplayWeChatData("您还没有绑定魔方账号,请您先绑定账号!"); } var msg = new WeChatData(); msg.CreateTime = DateTime.Now.ToFileTime().ToString(); msg.ToUserName = data.FromUserName; msg.FromUserName = data.ToUserName; msg.MsgType = "text"; if (ModelFacade.WeChat.WeChatModel.UnBind(data.FromUserName)) { msg.Content = "取消绑定成功!"; } else { msg.Content = "取消绑定失败!"; } return msg.ToXml(); }
public string Excute(WeChatConfig config, WeChatData data) { if (!ModelFacade.WeChat.WeChatModel.CheckIsBind(data.FromUserName)) { return data.ToQuicklyReplayWeChatData("您还没有绑定魔方账号,请您先绑定账号!"); } var vehicles = ModelFacade.WeChat.WeChatModel.GetDevicesByOpenID(7, data.FromUserName); if (vehicles.Count == 0) { return data.ToQuicklyReplayWeChatData("您还没有关联有车辆!"); } var list = vehicles.Select(p => { var isFortify = ModelFacade.WeChat.WeChatModel.CheckDeviceIsFortify(p.VehicleCode); var wid = new WeChatItemData() { Title = p.LicenceNumber + "(" + (isFortify ? "设防中" : "未设防") + ")", Url = string.Format("{0}WeChat/DeviceFortify?vehicleCode={1}&openID={2}&isFortify={3}", config.Host, p.VehicleCode, data.FromUserName, !isFortify) }; return wid; }).ToList(); list.Add(new WeChatItemData() { Title = "更多车辆", Url = string.Format("{0}WeChat/DeviceMore?openID={1}&type=DeviceFortify", config.Host, data.FromUserName) }); list.Insert(0, new WeChatItemData() { Title = "设防撤防", PicUrl = string.Format("{0}Content/WeChat/images/fortify.png", config.Host) }); return data.ToNewsWeChatData(list); }
public string Excute(WeChatConfig config, WeChatData data) { HttpHelper http = new HttpHelper(); HttpItem item = new HttpItem(); item.URL = string.Format("{0}menu/get?access_token={1}", config.APIUrl, config.AccessToken); item.Method = "GET"; item.ContentType = "application/x-www-form-urlencoded"; string result = http.GetHtml(item); return result; }
public string Excute(WeChatConfig config, WeChatData data) { if (!ModelFacade.WeChat.WeChatModel.CheckIsBind(data.FromUserName)) { return data.ToQuicklyReplayWeChatData("您还没有绑定魔方账号,请您先绑定账号!"); } var vehicles = ModelFacade.WeChat.WeChatModel.GetDevicesByOpenID(7, data.FromUserName); if (vehicles.Count == 0) { return data.ToQuicklyReplayWeChatData("您还没有关联有车辆!"); } var list = vehicles.Select(p => new WeChatItemData() { Title = p.LicenceNumber, Url = string.Format("{0}WeChat/DeviceReport?vehicleCode={1}&openID={2}", config.Host, p.VehicleCode, data.FromUserName) }).ToList(); list.Add(new WeChatItemData() { Title = "更多车辆", Url = string.Format("{0}WeChat/DeviceMore?openID={1}&type=DeviceReport", config.Host, data.FromUserName) }); list.Insert(0, new WeChatItemData() { Title = "查看车辆里程报表", PicUrl = string.Format("{0}Content/WeChat/images/report.png", config.Host) }); return data.ToNewsWeChatData(list); }
public string Excute(WeChatConfig config, WeChatData data) { if (ModelFacade.WeChat.WeChatModel.CheckIsBind(data.FromUserName)) { return data.ToQuicklyReplayWeChatData("您已经绑定过了!"); } else { var list = new List<WeChatItemData>() { new WeChatItemData() { Title="绑定帐号(魔方)", Url=string.Format("{0}WeChat/DeviceBind?openID={1}", config.Host, data.FromUserName), PicUrl= string.Format( "{0}Content/WeChat/images/bind.png",config.Host), Description="点击我绑定" } }; return data.ToNewsWeChatData(list); } }
/// <summary> /// 点击绑定 /// </summary> /// <param name="data"></param> /// <returns></returns> private string ClickBDZH(WeChatData data) { if (CheckIsBind(data.FromUserName)) { return data.ToQuicklyReplayWeChatData("您已经绑定过了!"); } else { var list = new List<WeChatItemData>() { new WeChatItemData() { Title="绑定帐号", Url=string.Format("{0}WeChat/Bind?weChatUserName={1}", _config.Host, data.FromUserName), PicUrl= string.Format( "{0}Areas/Gps/Content/Images/WeChat/bind.png",_config.Host), Description="点击我绑定" } }; return data.ToNewsWeChatData(list); } }
/// <summary> /// 取消绑定 /// </summary> /// <param name="data"></param> /// <returns></returns> private string ClickQXBD(WeChatData data) { if (!CheckIsBind(data.FromUserName)) { return data.ToQuicklyReplayWeChatData("您还没有绑定平台账号!"); } var msg = new WeChatData(); msg.CreateTime = DateTime.Now.ToFileTime().ToString(); msg.ToUserName = data.FromUserName; msg.FromUserName = data.ToUserName; msg.MsgType = "text"; if (UnBind(data.FromUserName)) { msg.Content = "取消绑定成功!"; } else { msg.Content = "取消绑定失败!"; } return msg.ToXml(); }
public string Excute(WeChatConfig config, WeChatData data) { HttpHelper http = new HttpHelper(); HttpItem item = new HttpItem(); item.URL = string.Format("{0}menu/delete?access_token={1}", config.APIUrl, config.AccessToken); item.Method = "GET"; string result = http.GetHtml(item); return result; }
private string Excute(WeChatData data) { if (!data.MsgType.HasValue()) return string.Empty; _logger.Info(data.ToJson()); switch (data.MsgType.ToLower()) { case "text": return this.ExcuteText(data); case "event": return this.ExcuteEvent(data); } return string.Empty; }
public string Excute(WeChatConfig config, WeChatData data) { return string.Empty; }