| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189 |
- using System;
- using System.Collections.Generic;
- using System.Text;
- using System.Web.Script.Serialization;
- namespace SiteCore
- {
- public partial class WxPush
- {
- private static readonly object miniAtObj = new object();
- public static string mini_appid = "wx968c99ff1498e09f";
- public static string mini_appsecret = "153afb0877ee60fecd7f5580c9182ee6";
- static string mini_sendUrl = "https://api.weixin.qq.com/cgi-bin/message/subscribe/send?access_token=";
- public static object getMiniAt(HttpHelper http)
- {
- object cat = WebCache.GetRunCache("miniAt");
- if (cat == null)
- {
- lock (miniAtObj)
- {
- //http = new HttpHelper();
- HttpItem item = new HttpItem()
- {
- URL = string.Format(tokenUrl, mini_appid, mini_appsecret)
- };
- HttpResult hResult = http.GetHtml(item);
- string html = hResult.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("miniAt", at, 100);
- cat = at;
- }
- }
- }
- return cat;
- }
- /// <summary>
- /// 通知工地订单已受理
- /// </summary>
- public static void NotifyGdHasGetMsg(string openid, string txt1, string txt2, string date1)
- {
- HttpHelper http = new HttpHelper();
- HttpResult hResult = null;
- object cat = getMiniAt(http);
- if (cat != null)
- {
- DateTime cTime = DateTime.Now;
- //txt1 = "部位:" + txt1;
- if (txt2.Length > 20) txt2 = txt2.Substring(0, 20);
- var tdata = new
- {
- thing1 = new TemplateItem(txt1),
- thing2 = new TemplateItem(txt2),
- date3 = new TemplateItem(date1)
- };
- var msgData = new MiniTemplateData()
- {
- touser = openid,
- template_id = "mJfJKxxb7XDDgWWlM-XMr9OPF2FRb_Z5gClsGs805AU",
- page = "pages/index",
- data = tdata
- };
- // miniprogram= minidata,
- string msg = Newtonsoft.Json.JsonConvert.SerializeObject(msgData);
- HttpItem item = new HttpItem()
- {
- URL = mini_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;
- }
- }
- //任务报名通知
- public static void sendTaskReceiveMsg(string openid, string form_id, object tid, string btime, string bname, string bphone, string bprice, string bmemo)
- {
- HttpHelper http = new HttpHelper();
- HttpResult hResult = null;
- object cat = getMiniAt(http);
- if (cat != null)
- {
- DateTime cTime = DateTime.Now;
- var tdata = new
- {
- keyword1 = new TemplateItem(btime, "#333333"),
- keyword2 = new TemplateItem(bname, "#0E7700"),
- keyword3 = new TemplateItem(bprice, "#0E7700"),
- keyword4 = new TemplateItem(bphone, "#333333"),
- keyword5 = new TemplateItem(bmemo, "#333333")
- };
- var msgData = new MiniTemplateData()
- {
- touser = openid,
- template_id = "3FJ8OG_oqQxCq97ZYwUsIOWTh7VkgpxHtuh0Hc9IKY4",
- form_id = form_id,
- page = "pages/bounty/bountyDetail?r=1&tid=" + tid,
- data = tdata
- };
- // miniprogram= minidata,
- string msg = Newtonsoft.Json.JsonConvert.SerializeObject(msgData);
- HttpItem item = new HttpItem()
- {
- URL = mini_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;
- }
- }
- //任务选中/取消选中通知
- public static void sendTaskChioceMsg(string openid, string form_id, object tid, string title, string con)
- {
- HttpHelper http = new HttpHelper();
- HttpResult hResult = null;
- object cat = getMiniAt(http);
- if (cat != null)
- {
- DateTime cTime = DateTime.Now;
- var tdata = new
- {
- keyword1 = new TemplateItem(title, "#333333"),
- keyword2 = new TemplateItem(con + " " + cTime.ToString("yyyy-MM-dd HH:mm:ss"), "#0E7700")
- };
- var msgData = new MiniTemplateData()
- {
- touser = openid,
- template_id = "rpvN7kE6vEWq8e4P1rvpWCGtPbxJUjXRmzKUO71zT4E",
- form_id = form_id,
- page = "pages/bounty/bountyDetail?r=1&tid=" + tid,
- data = tdata
- };
- // miniprogram= minidata,
- string msg = Newtonsoft.Json.JsonConvert.SerializeObject(msgData);
- HttpItem item = new HttpItem()
- {
- URL = mini_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;
- }
- }
- }
- public class MiniTemplateData
- {
- public string touser { get; set; }
- public string template_id { get; set; }
- public string page { get; set; }
- public object form_id { get; set; }
- public object data { get; set; }
- //public string emphasis_keyword { get; set; }
- }
- }
|