/// <summary> /// 创建临时二维码 /// </summary> private void CreateTmpQRCode() { string errmsg = ""; string wxappid = WXApiInfo.wxappid; int scene_id = 0; BLLSequence myseq = new BLLSequence(); bool result = myseq.GetCreateTmpQRCodeScene_id(ref scene_id, ref errmsg); if (result) { CreateQRCodeResult info = new CreateQRCodeResult(); CallWXInterface mybll = new CallWXInterface(); DateTime failuredate = DateTime.Now.AddSeconds(3600); info = mybll.CreateTmpQRCode(wxappid, 3600, scene_id); BLLQRManage myqr = new BLLQRManage(); result = myqr.CreateTmpQRCode(info.ticket, info.expire_seconds, info.url, 0, scene_id, "绑定用户", failuredate, ref errmsg); if (result) { string str = "\"url\":\"" + info.url + "\""; Response.Write(outjson.Replace("#code#", "0").Replace("#msg#", "").Replace("\"data\":null", str)); Response.End(); } else { Response.Write(outjson.Replace("#code#", "-1").Replace("#msg#", errmsg)); Response.End(); } } else { Response.Write(outjson.Replace("#code#", "-1").Replace("#msg#", errmsg)); Response.End(); } }
/// <summary> /// 发送系统状态通知 /// </summary> /// <returns></returns> public bool SendSysStatusNotify(string wxappid, string wxopenid, string keyword1, string keyword2, string keyword3, ref string errmsg) { bool result = true; string wxtemplateid = "z3-WMAJWRf_jCZzZCdm8Nyh7gI1rqR59G0BY6-g_3PM"; //string url = "http://2308028y7r.51mypc.cn/Default.aspx"; string first = "您好,项目进度已发生变化,请及时查阅"; string remark = "点击查看详情"; #region 模板消息发送格式 string WXNoticeTemplate = @"{{ ""touser"":""{0}"", ""template_id"":""{1}"", ""url"":""{2}"", ""data"":{{ ""first"":{{ ""value"":""{3}"", ""color"":""#ff0000"" }}, ""keyword1"":{{ ""value"":""{4}"", ""color"":""#000000"" }}, ""keyword2"":{{ ""value"":""{5}"", ""color"":""#000000"" }}, ""keyword3"":{{ ""value"":""{6}"", ""color"":""#000000"" }}, ""remark"":{{ ""value"":""{7}"", ""color"":""#000000"" }} }} }}"; string sendWXTemplate = string.Format(WXNoticeTemplate, new object[] { wxopenid, wxtemplateid, "", first, keyword1, keyword2, keyword3, remark }); #endregion try { CallWXInterface call = new CallWXInterface(); Ent_TemplateMsgSendResult sendresult = call.SendTemplateMessage(wxappid, sendWXTemplate); if (sendresult.errcode == 0) { } } catch (Exception ex) { } return(result); }
/// <summary> /// 推送绑定消息 /// </summary> /// <returns></returns> public bool SendSys(string wxappid, string wxopenid, string keyword1, string keyword2, string keyword3, ref string errmsg) { bool result = true; string wxtemplateid = "s709f8hBQOmnfAGvSHCuhFMjn63g0nL_iC3PSXVRnOs"; string url = "http://240344pb55.qicp.vip/WebForm1.aspx"; string first = "您好,新的绑定请求,请及时查阅"; string remark = "点击查看详情"; #region 模板消息发送格式 string WXNoticeTemplate = @"{{ ""touser"":""{0}"", ""template_id"":""{1}"", ""url"":""{2}"", ""data"":{{ ""first"":{{ ""value"":""{3}"", ""color"":""#ff0000"" }}, ""keyword1"":{{ ""value"":""{4}"", ""color"":""#000000"" }}, ""keyword2"":{{ ""value"":""{5}"", ""color"":""#000000"" }}, ""keyword3"":{{ ""value"":""{6}"", ""color"":""#000000"" }}, ""remark"":{{ ""value"":""{7}"", ""color"":""#000000"" }} }} }}"; string sendWXTemplate = string.Format(WXNoticeTemplate, new object[] { wxopenid, wxtemplateid, url, first, keyword1, keyword2, keyword3, remark }); #endregion try { CallWXInterface call = new CallWXInterface(); Ent_TemplateMsgSendResult sendresult = call.SendTemplateMessage(wxappid, sendWXTemplate); if (sendresult.errcode == 0) { } } catch (Exception ex) { } return(result); }
/// <summary> /// 推送绑定消息 /// </summary> /// <returns></returns> public bool SendSecss(string wxappid, string wxopenid, string keyword1, string keyword2, ref string errmsg) { bool result = true; string wxtemplateid = "PriZgAb1D7tSC6ZSgsCSKLzu8m2gBPEGtWijXKr024Q"; string url = "http://240344pb55.qicp.vip/WX/re_login.aspx";//这里换登录空白页 string first = "您好,绑定已允许,可放行登录"; string remark = "点击查看详情"; #region 模板消息发送格式 string WXNoticeTemplate = @"{{ ""touser"":""{0}"", ""template_id"":""{1}"", ""url"":""{2}"", ""data"":{{ ""first"":{{ ""value"":""{3}"", ""color"":""#ff0000"" }}, ""keyword1"":{{ ""value"":""{4}"", ""color"":""#000000"" }}, ""keyword2"":{{ ""value"":""{5}"", ""color"":""#000000"" }}, ""remark"":{{ ""value"":""{6}"", ""color"":""#000000"" }} }} }}"; string sendWXTemplate = string.Format(WXNoticeTemplate, new object[] { wxopenid, wxtemplateid, url, first, keyword1, keyword2, remark }); #endregion try { CallWXInterface call = new CallWXInterface(); Ent_TemplateMsgSendResult sendresult = call.SendTemplateMessage(wxappid, sendWXTemplate); if (sendresult.errcode == 0) { } } catch (Exception ex) { } return(result); }
/// <summary> /// 推送绑定消息 /// </summary> /// <returns></returns> public bool Sendfalse(string wxappid, string wxopenid, string keyword1, string keyword2, ref string errmsg) { bool result = true; string wxtemplateid = "1MpRPdqSxpNwp8zIABiIHILo6TzH2m6cgK4kXpYhXX8"; //string url = "http://240344pb55.qicp.vip/WebForm1.aspx"; string first = "您好,绑定被驳回,请及时联系管理员"; // string remark = "点击查看详情"; #region 模板消息发送格式 string WXNoticeTemplate = @"{{ ""touser"":""{0}"", ""template_id"":""{1}"", ""url"":""{2}"", ""data"":{{ ""first"":{{ ""value"":""{3}"", ""color"":""#ff0000"" }}, ""keyword1"":{{ ""value"":""{4}"", ""color"":""#000000"" }}, ""keyword2"":{{ ""value"":""{5}"", ""color"":""#000000"" }} }} }}"; string sendWXTemplate = string.Format(WXNoticeTemplate, new object[] { wxopenid, wxtemplateid, "", first, keyword1, keyword2 }); #endregion try { CallWXInterface call = new CallWXInterface(); Ent_TemplateMsgSendResult sendresult = call.SendTemplateMessage(wxappid, sendWXTemplate); if (sendresult.errcode == 0) { } } catch (Exception ex) { } return(result); }
/// <summary> /// 处理二维码扫描事件 /// </summary> /// <param name="xmlModel"></param> /// <returns></returns> public string ScanHandle(ref Dictionary <string, string> xmlModel) { string result = ""; //返回欢迎语内容 string wxappusername = xmlModel["ToUserName"]; //事件发给哪个开发者微信号(注意这里不是公众号的AppID,而是公众号的微信号) string wxopenid = xmlModel["FromUserName"]; //事件是哪个粉丝发起的(粉丝的openid) string strCreateTime = xmlModel["CreateTime"]; if (string.IsNullOrEmpty(strCreateTime)) { //无消息创建时间,无法排重,放弃处理 return(""); } double wxcreatetime; if (!double.TryParse(strCreateTime, out wxcreatetime)) { //无法将createtime转换成功,无法排重,放弃处理 return(""); } string wxappid = ""; DALWXMessageHandleBasic mydal = new DALWXMessageHandleBasic(); //事件消息排重 bool success = true; success = mydal.EventMsgPreventDuplicates(wxopenid, wxcreatetime); if (!success) { //事件消息排重失败,放弃处理 return(""); } wxappid = WXApiInfo.wxappid; CallWXInterface wxinterface = new CallWXInterface(); //获取粉丝信息,这一步是必须的,也要在明文模式下,要防止虚构粉丝数据 WXFansInfo wxuser = wxinterface.GetUserInfo(wxappid, wxopenid); if (wxuser == null || wxuser.errcode != 0) { return(""); } //推送过来的二维码场景值 string EventKey = ""; if (xmlModel.ContainsKey("EventKey")) { EventKey = xmlModel["EventKey"]; } //result = QRCodeApplication(wxopenid, EventKey.Replace("qrscene_", ""), wxuser); string errmsg = ""; BLLWXFansManage mybll = new BLLWXFansManage(); success = mybll.QRCodeApplication(wxopenid, EventKey.Replace("qrscene_", ""), wxuser, ref errmsg); if (success) { result = errmsg; } else { result = errmsg; } //返回文本消息 string rspxml = ""; if (!string.IsNullOrEmpty(result)) { rspxml = "<xml><ToUserName><![CDATA[" + xmlModel["FromUserName"] + "]]></ToUserName><FromUserName><![CDATA[" + xmlModel["ToUserName"] + "]]></FromUserName><CreateTime>" + xmlModel["CreateTime"] + "</CreateTime><MsgType><![CDATA[text]]></MsgType><Content><![CDATA[" + result + "]]></Content><FuncFlag>0</FuncFlag></xml>"; } return(rspxml); }
/// <summary> /// 处理关注事件 /// </summary> /// <param name="xmlModel"></param> /// <returns></returns> public string SubscribeHandle(ref Dictionary <string, string> xmlModel) { string result = ""; //返回欢迎语内容 string wxappusername = xmlModel["ToUserName"]; //事件发给哪个开发者微信号(注意这里不是公众号的AppID,而是公众号的微信号) string wxopenid = xmlModel["FromUserName"]; //事件是哪个粉丝发起的(粉丝的openid) string strCreateTime = xmlModel["CreateTime"]; if (string.IsNullOrEmpty(strCreateTime)) { //无消息创建时间,无法排重,放弃处理 return(""); } double wxcreatetime; if (!double.TryParse(strCreateTime, out wxcreatetime)) { //无法将createtime转换成功,无法排重,放弃处理 return(""); } string wxappid = ""; DALWXMessageHandleBasic mydal = new DALWXMessageHandleBasic(); //事件消息排重 bool success = true; success = mydal.EventMsgPreventDuplicates(wxopenid, wxcreatetime); if (!success) { //事件消息排重失败,放弃处理 return(""); } wxappid = WXApiInfo.wxappid; CallWXInterface wxinterface = new CallWXInterface(); //获取粉丝信息,这一步是必须的,因为在明文模式下,要防止虚构粉丝数据 WXFansInfo wxuser = wxinterface.GetUserInfo(wxappid, wxopenid); if (wxuser == null || wxuser.errcode != 0) { return(""); } //根据微信POST过来的事件数据,判断是普通关注还是带参数的二维码关注,如果是带参数二维码关注,需要读取相应的二维码应用信息 string EventKey = ""; if (xmlModel.ContainsKey("EventKey")) { EventKey = xmlModel["EventKey"]; } //注意微信的坑:普通关注的事件是有EventKey的(而文档上面没有)。带参数二维码扫描关注的EventKey是qrscene_开头的。 #region 根据二维码应用信息来处理 //WXUser bllWXUser = new WXUser(); if (string.IsNullOrEmpty(EventKey) || !TextValidation.CheckStringByRegexp(EventKey, "qrscene_.+")) { //普通关注 string errmsg = ""; BLLWXFansManage mybll = new BLLWXFansManage(); mybll.SubscribeLog(wxopenid, 1, ref errmsg);//关注日志 success = mybll.Subscribe(wxopenid, wxuser, ref errmsg); if (success) { result = "欢迎关注每通系统!"; } else { result = errmsg; } } else { //二维码扫描 //result = QRCodeApplication(wxopenid, EventKey.Replace("qrscene_", ""), wxuser); string errmsg = ""; BLLWXFansManage mybll = new BLLWXFansManage(); mybll.SubscribeLog(wxopenid, 1, ref errmsg);//关注日志 success = mybll.QRCodeApplication(wxopenid, EventKey.Replace("qrscene_", ""), wxuser, ref errmsg); if (success) { result = errmsg; } else { result = errmsg; } } #endregion //因为对于关注粉丝,可以自动发送欢迎语或其他内容,所以这里可返回内容 string rspxml = ""; if (!string.IsNullOrEmpty(result)) { rspxml = "<xml><ToUserName><![CDATA[" + xmlModel["FromUserName"] + "]]></ToUserName><FromUserName><![CDATA[" + xmlModel["ToUserName"] + "]]></FromUserName><CreateTime>" + xmlModel["CreateTime"] + "</CreateTime><MsgType><![CDATA[text]]></MsgType><Content><![CDATA[" + result + "]]></Content><FuncFlag>0</FuncFlag></xml>"; } return(rspxml); }
/// <summary> /// 预订单下达通知 /// </summary> /// <returns></returns> public bool SendOrderNotify(string wxappid, string wxopenid, string 订单号, string 产品名称, string 数量, string 图纸下达日期, string 收件人, ref string errmsg) { bool result = true; string wxtemplateid = "NiYXhNLAdfzm-e7VyByRH0EdF61Xr_dqU4bMhfpz6bI"; //string url = "http://2308028y7r.51mypc.cn/AdvanceOrder/AddAdvanceOrder.aspx"; string first = "您好,新图纸已完成设计"; string remark = "点击查看详情"; #region 模板消息发送格式 string WXNoticeTemplate = @"{{ ""touser"":""{0}"", ""template_id"":""{1}"", ""url"":""{2}"", ""topcolor"":""#FF0000"", ""data"":{{ ""first"":{{ ""value"":""{3}"", ""color"":""#ff0000"" }}, ""keyword1"":{{ ""value"":""{4}"", ""color"":""#000000"" }}, ""keyword2"":{{ ""value"":""{5}"", ""color"":""#000000"" }}, ""keyword3"":{{ ""value"":""{6}"", ""color"":""#000000"" }}, ""keyword4"":{{ ""value"":""{7}"", ""color"":""#000000"" }}, ""keyword5"":{{ ""value"":""{8}"", ""color"":""#000000"" }}, ""remark"":{{ ""value"":""{9}"", ""color"":""#000000"" }} }} }}"; string sendWXTemplate = string.Format(WXNoticeTemplate, new object[] { wxopenid, wxtemplateid, "", first, 订单号, 产品名称, 数量, 图纸下达日期, 收件人, remark }); #endregion try { CallWXInterface call = new CallWXInterface(); Ent_TemplateMsgSendResult sendresult = call.SendTemplateMessage(wxappid, sendWXTemplate); if (sendresult.errcode == 0) { } } catch (Exception ex) { } return(result); }