| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300 |
- using BizCom;
- using System;
- using System.Collections.Generic;
- using System.Text;
- using System.Web.Script.Serialization;
- namespace SiteCore
- {
- public partial class WxPush
- {
- //public static string
- public static string appid = "wx20432512482565e9";
- public static string appsecret = "07492bc9cbbc5b303e5e135b4dccd6f0";
- public static string hy_appid = "wx0669fa53c6f74698";
- public static string hy_appsecret = "678776d4eec59ce289eb88ff36f3b4ef";
- static string tokenUrl = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid={0}&secret={1}";
- static string sendUrl = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=";
- static object atObj = new Object();
- private static object getAt(HttpHelper http)
- {
- object cat = WebCache.GetRunCache("hyAt");
- if (cat == null)
- {
- lock (atObj)
- {
- //http = new HttpHelper();
- HttpItem item = new HttpItem()
- {
- URL = string.Format(tokenUrl, hy_appid, hy_appsecret)
- };
- HttpResult hResult = http.GetHtml(item);
- string html = hResult.Html;
- XLog.SaveLog(0, "getAt:" + html);
- JavaScriptSerializer jss = new JavaScriptSerializer();
- Dictionary<string, object> jObj = jss.Deserialize<Dictionary<string, object>>(html);
- if (!jObj.ContainsKey("errcode"))
- {
- string at = jObj["access_token"].ToString();
- WebCache.AddRunCacheTime("hyAt", at, 100);
- cat = at;
- }
- }
- }
- return cat;
- }
- public static void sendMonitorMsg(string title, string openid)
- {
- HttpHelper http = new HttpHelper();
- HttpResult hResult = null;
- object cat = getAt(http);
- if (cat != null)
- {
- var tdata = new
- {
- first = new TemplateItem(title, "#333333"),
- keyword1 = new TemplateItem(title, "#333333"),
- keyword2 = new TemplateItem(DateTime.Now.ToString("yyyy-MM-dd HH:mm"), "#0E7700"),
- remark = new TemplateItem("请注意查看", "#333333")
- };
- //var minidata = new
- //{
- // appid = "wx20432512482565e9",
- // pagepath = "pages/lab/lab?remind=1"
- //};
- var msgData = new TemplateData()
- {
- touser = openid,
- template_id = "Tsp5iFvM_L1Ok10nta3TvQzjnrZvas7PKIWbdX1t08M",
- url = "",
- data = tdata
- };
- // miniprogram= minidata,
- string msg = Newtonsoft.Json.JsonConvert.SerializeObject(msgData);
- HttpItem item = new HttpItem()
- {
- URL = sendUrl + cat,
- Method = "POST",
- ContentType = "application/json",
- Postdata = msg,
- PostEncoding = Encoding.UTF8,
- Encoding = Encoding.UTF8
- };
- //item.Encoding = Encoding.UTF8;
- hResult = http.GetHtml(item);
- string html = hResult.Html;
- XLog.SaveLog(0, html);
- }
- }
- public static void sendSignDispatchMsg(string openid, string key1, string key2, string memo)
- {
- HttpHelper http = new HttpHelper();
- HttpResult hResult = null;
- object cat = getAt(http);
- if (cat != null)
- {
- var tdata = new
- {
- first = new TemplateItem("您的电子小票已签收", "#333333"),
- keyword1 = new TemplateItem(key1, "#333333"),
- keyword2 = new TemplateItem(key2, "#0E7700"),
- keyword3 = new TemplateItem(DateTime.Now.ToString("yyyy-MM-dd HH:mm"), "#0E7700"),
- remark = new TemplateItem(memo, "#333333")
- };
- var minidata = new
- {
- appid = mini_appid,
- pagepath = "pages/index"
- };
- var msgData = new TemplateData()
- {
- touser = openid,
- template_id = "uDUEkjJt4-j2m9PhIB6bTXeLZrAvvNdi7a2xMBXzH1I",
- url = "",
- miniprogram = minidata,
- data = tdata
- };
- string msg = Newtonsoft.Json.JsonConvert.SerializeObject(msgData);
- HttpItem item = new HttpItem()
- {
- URL = sendUrl + cat,
- Method = "POST",
- ContentType = "application/json",
- Postdata = msg,
- PostEncoding = Encoding.UTF8,
- Encoding = Encoding.UTF8
- };
- //item.Encoding = Encoding.UTF8;
- hResult = http.GetHtml(item);
- string html = hResult.Html;
- }
- }
- #region xiu
- public static void sendXiuPersonMsg(string openids, string cust, string con, string notify)
- {
- if (openids == "") return;
- string[] oArr = openids.Split(',');
- for (int i = 0; i < oArr.Length; i++)
- {
- sendXiuPersonMsg(oArr[i], "有新的维修单待受理", cust, con, notify, "请注意查看");
- }
- }
- public static void sendXiuPersonMsg(string openid, string first, string cust, string con, string notify, string remark)
- {
- HttpHelper http = new HttpHelper();
- HttpResult hResult = null;
- object cat = getAt(http);
- if (cat != null)
- {
- var tdata = new
- {
- first = new TemplateItem(first, "#333333"),
- keyword1 = new TemplateItem(cust, "#333333"),
- keyword2 = new TemplateItem(con, "#0E7700"),
- keyword3 = new TemplateItem(DateTime.Now.ToString("yyyy-MM-dd HH:mm"), "#0E7700"),
- keyword4 = new TemplateItem(notify, "#0E7700"),
- remark = new TemplateItem(remark, "#333333")
- };
- //var minidata = new
- //{
- // appid = "wx20432512482565e9",
- // pagepath = "pages/lab/lab?remind=1"
- //};
- var msgData = new TemplateData()
- {
- touser = openid,
- template_id = "0sbCmaWrhC-5v_jL7z0-BR7PtrKJ75E74E2WJuu4Wk8",
- url = "",
- data = tdata
- };
- // miniprogram= minidata,
- string msg = Newtonsoft.Json.JsonConvert.SerializeObject(msgData);
- HttpItem item = new HttpItem()
- {
- URL = sendUrl + cat,
- Method = "POST",
- ContentType = "application/json",
- Postdata = msg,
- PostEncoding = Encoding.UTF8,
- Encoding = Encoding.UTF8
- };
- //item.Encoding = Encoding.UTF8;
- hResult = http.GetHtml(item);
- string html = hResult.Html;
- XLog.SaveLog(0, html);
- }
- }
- public static void sendXiuCorpMsg(string openids, string type, string state, string log)
- {
- if (openids == "") return;
- string[] oArr = openids.Split(',');
- for (int i = 0; i < oArr.Length; i++)
- {
- sendXiuCorpMsg(oArr[i], "您的售后服务有新的进展", type, state, log, "请注意查看");
- }
- }
- public static void sendXiuCorpMsg(string openid, string first, string type, string state, string log, string remark)
- {
- HttpHelper http = new HttpHelper();
- HttpResult hResult = null;
- object cat = getAt(http);
- if (cat != null)
- {
- var tdata = new
- {
- first = new TemplateItem(first, "#333333"),
- HandleType = new TemplateItem(type, "#333333"),
- Status = new TemplateItem(state, "#0E7700"),
- RowCreateDate = new TemplateItem(DateTime.Now.ToString("yyyy-MM-dd HH:mm"), "#0E7700"),
- LogType = new TemplateItem(log, "#0E7700"),
- remark = new TemplateItem(remark, "#333333")
- };
- //var minidata = new
- //{
- // appid = "wx20432512482565e9",
- // pagepath = "pages/lab/lab?remind=1"
- //};
- var msgData = new TemplateData()
- {
- touser = openid,
- template_id = "_OsQ7mmYeEjq3GsZDZVVnZDh5iIw_jbp7nUlkTTfwsk",
- url = "",
- data = tdata
- };
- // miniprogram= minidata,
- string msg = Newtonsoft.Json.JsonConvert.SerializeObject(msgData);
- HttpItem item = new HttpItem()
- {
- URL = sendUrl + cat,
- Method = "POST",
- ContentType = "application/json",
- Postdata = msg,
- PostEncoding = Encoding.UTF8,
- Encoding = Encoding.UTF8
- };
- //item.Encoding = Encoding.UTF8;
- hResult = http.GetHtml(item);
- string html = hResult.Html;
- XLog.SaveLog(0, html);
- }
- }
- #endregion
- }
- }
- public class TemplateData
- {
- public string touser { get; set; }
- public string template_id { get; set; }
- public string topcolor { get; set; }
- public string url { get; set; }
- public object data { get; set; }
- public object miniprogram { get; set; }
- }
- public class TemplateItem
- {
- public string value { get; set; }
- public string color { get; set; }
- public TemplateItem(string _value)
- {
- value = _value;
- }
- public TemplateItem(string _value, string _color)
- {
- value = _value;
- color = _color;
- }
- }
|