| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124 |
- using BizCom;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Web;
- using System.Web.Caching;
- using System.Web.Script.Serialization;
- namespace SiteCore
- {
- public class XiuNotifyHelper
- {
- static object miniAtObj = new Object();
- 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=";
- public static string mini_appid = "wxee687601b460ac2f";
- public static string mini_appsecret = "ed1195446aa6fadc7c84d726de8ea699";
- static string mini_sendUrl = "https://api.weixin.qq.com/cgi-bin/message/wxopen/template/send?access_token=";
- public static void AddRunCacheTime(string cKey, object cValue, double cTime)
- {
- if (HttpRuntime.Cache[cKey] == null && cValue != null)//HttpContext.Current.Cache.Remove(cKey);
- HttpRuntime.Cache.Add(cKey, cValue, null, DateTime.Now.AddMinutes(cTime), TimeSpan.Zero, CacheItemPriority.Normal, null);
- }
- public static object GetRunCache(string cKey)
- {
- return HttpRuntime.Cache[cKey];
- }
- public static void RemoveRunCache(string cKey)
- {
- if (HttpRuntime.Cache[cKey] != null)
- HttpRuntime.Cache.Remove(cKey);
- }
- public static object getMiniAt(HttpHelper http)
- {
- object cat = GetRunCache("xiuminiAt");
- 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();
- AddRunCacheTime("xiuminiAt", at, 100);
- cat = at;
- }
- }
- }
- return cat;
- }
- public static void sendReceiveMsg(string openid, string formid, SXiuRecord entity)
- {
- //if (sArr.Length < 7 || sArr[6] == "") return;
- //if (!lst.Contains("'" + sArr[6] + "'")) lst.Add("'" + sArr[6] + "'");
- //if (sArr[6] == "the formId is a mock one") return;
- HttpHelper http = new HttpHelper();
- HttpResult hResult = null;
- object cat = getMiniAt(http);
- if (cat != null)
- {
- DateTime cTime = DateTime.Now;
- //订单号{ { keyword1.DATA} }
- //订单信息{ { keyword2.DATA} }
- //确认时间{ { keyword3.DATA} }
- //联系人{ { keyword4.DATA} }
- //备注{ { keyword5.DATA} }
- //订单内容{ { keyword6.DATA} }
- //订单状态{ { keyword7.DATA} }
- var tdata = new
- {
- keyword1 = new TemplateItem(entity.Code, "#333333"),
- keyword2 = new TemplateItem(entity.XiuTypeInfo, "#0E7700"),
- keyword3 = new TemplateItem("如有需要会电话联系您", "#2148CD"),
- keyword4 = new TemplateItem("请保持手机通讯通畅", "#000000"),
- keyword5 = new TemplateItem("已受理", "#000000"),
- };
- var msgData = new MiniTemplateData()
- {
- touser = openid,
- template_id = "xPqCAfPQFr3D_6sI_eFppuJKCVxsgpIOO97V2ExdVdk",
- form_id = formid,
- page = "pages/orders/orders",
- 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;
- }
- }
- }
- }
|