123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227 |
- using Common;
- using Common.Model;
- using Common.Wechat;
- using CoreEntity.Entity;
- using JCSoft.WX.Framework.Api;
- using JCSoft.WX.Framework.Extensions;
- using JCSoft.WX.Framework.Models;
- using JCSoft.WX.Framework.Models.ApiRequests;
- using JCSoft.WX.Framework.Models.ApiResponses;
- using JCSoft.WX.Framework.Models.Exceptions;
- using Newtonsoft.Json;
- using System;
- using System.Collections.Generic;
- using System.Data;
- using System.Data.SqlClient;
- using System.Text;
- using System.Threading.Tasks;
- using ZcPeng.PublicLibrary;
- using ZcPeng.weixin.PublicAccount;
- namespace CoreEntity.TimeJob
- {
- public class TimeTask
- {
- private int _id;
- private string _hour;
- private string _minute;
- private string _second;
- public TimeTask()
- {
- }
- public int Id
- {
- get { return _id; }
- set { _id = value; }
- }
- public string Hour
- {
- get { return _hour; }
- set { _hour = value; }
- }
- public string Minute
- {
- get { return _minute; }
- set { _minute = value; }
- }
- public string Second
- {
- get { return _second; }
- set { _second = value; }
- }
- public static Message sendSupplyMassMesage(IApiClient _client,
- Int32 PushAccountId,
- string RecordId,//
- string GoodsName,
- string StoreGapNums,
- string TotalAmount,
- ////string GoodsSpec,
- ////string BrandName,
- ////decimal LastPrice,
- DateTime EndTime)
- {
- string accountName = string.Empty;
- string accountPassword = string.Empty;
- string WxOpenId = "";
- //用户账户,密码
- #region 获取user
- string result = "";
- DataTable dt = new DataTable();
- string commandTextUser = "Select roleId,accountName,AccountPhone,AccountPassWord,WxOpenId From "
- + Config.TablePrefix + "Account Where Id=@PushAccountId";
- List<List<Object>> parametersRecord = new List<List<Object>>();
- parametersRecord.Add(new List<Object>() { "PushAccountId", PushAccountId });
- List<SqlParameter> parameters1 = DataAccess.ToParameters(parametersRecord);
- bool result1 = DataAccess.GetValues(commandTextUser, ref dt, parameters1.ToArray(), out result);
- List<Account> users = new List<Account>();
- if (dt != null && dt.Rows.Count > 0)
- {
- // 把DataTable转换为IList<UserInfo>
- users = (List<Account>)ModelConvertHelper<Account>.ConvertToModel(dt);
- accountName = users.ToArray()[0].AccountName;
- accountPassword = users.ToArray()[0].AccountPassWord;
- WxOpenId = users.ToArray()[0].WxOpenId;
- }
- #endregion
- if(WxOpenId != "" && WxOpenId != null) {
- #region 推送信息
- //ErrorMessage errorMessage;
- //long message = -1;
- //string content = "我们有新的采购需求:"+""
- // +",请登陆:http:///coop.360lj.com:8000 填写您的可供货数量";
- //message = MassMessage.Send(Config.WeChatAppName, true, "group", MassMessageTypeEnum.text,
- // content, out errorMessage);
- Dictionary<string, TemplateDataProperty> temp = new Dictionary<string, TemplateDataProperty>();
- TemplateDataProperty tmpdatap = new TemplateDataProperty();
- tmpdatap.Value = "采购需求推送:";
- tmpdatap.Color = "#173177";
- temp.Add("first", tmpdatap);
- //产品品种需求数量
- tmpdatap = new TemplateDataProperty();
- tmpdatap.Value = GoodsName;
- tmpdatap.Color = "#173177";
- temp.Add("keyword1", tmpdatap);
-
- //tmpdatap = new TemplateDataProperty();
- //tmpdatap.Value = GoodsSpec;
- //tmpdatap.Color = "#173177";
- //temp.Add("GoodsSpec", tmpdatap);
- //tmpdatap = new TemplateDataProperty();
- //tmpdatap.Value = StoreGapNum.ToString();
- //tmpdatap.Color = "#173177";
- //temp.Add("StoreGapNum", tmpdatap);
- //tmpdatap = new TemplateDataProperty();
- //tmpdatap.Value = LastPrice.ToString();
- //tmpdatap.Color = "#173177";
- //temp.Add("LastPrice", tmpdatap);
- tmpdatap = new TemplateDataProperty();
- tmpdatap.Value = StoreGapNums;
- tmpdatap.Color = "#173177";
- temp.Add("keyword2", tmpdatap);
- tmpdatap = new TemplateDataProperty();
- tmpdatap.Value = TotalAmount;
- tmpdatap.Color = "#173177";
- temp.Add("keyword3", tmpdatap);
- tmpdatap = new TemplateDataProperty();
- tmpdatap.Value = "https://" + Config.Host;
- tmpdatap.Color = "#173177";
- temp.Add("keyword4", tmpdatap);
- tmpdatap = new TemplateDataProperty();
- string content = "请登陆我们的系统填写可供货数量:http://" + Config.Host + ":8000" +
- " 账户:" + accountName +
- " 密码:" + accountPassword +
- " 截止时间:" + EndTime.ToString()
- ;
- tmpdatap.Value = content;
- tmpdatap.Color = "#173177";
- temp.Add("remark", tmpdatap);
- //加入测试公众号
- AccountInfo account = new AccountInfo(Config.WeChatAppName,
- Config.WeChatAppKey, Config.WeChatAppSecret, null, null);
- AccountInfoCollection.SetAccountInfo(account);
- //加入正式公众号
- //AccountInfoCollection.SetAccountInfo(new AccountInfo("YourId2", "AppId", "AppSecret", "Token", "EncodingAesKey", "非測試"));
- ZcPeng.weixin.PublicAccount.AccessToken token = ZcPeng.weixin.PublicAccount.AccessToken.Get(Config.WeChatAppName);
- if (token == null)
- {
- ErrorMessage errorMessage = new ErrorMessage(ErrorMessage.ExceptionCode, "获取许可令牌失败。");
- Message msg = new Message(Guid.NewGuid(), MessageType.Request, errorMessage.errcode == 0 ? "" : errorMessage.errcode.ToString(),
- DateTime.Now, "TemplateSend", errorMessage.errcode + ":" +errorMessage.errmsg);
- Message.Insert(msg);
- return null;
- }
- var request = new TemplateSendRequest
- {
- AccessToken = token.access_token,
- ToUser = WxOpenId,
- TemplateID = "SnuX3WGoLBBEUs9wnwyqur0ocdypUk2euX45BIj9JKk",
- TopColor = "#FF0000",
- Url = "https://" + Config.Host + "/web/supplymobile/listData?RecordId=" + RecordId,
- Data = temp,
- };
- Log log = new Log(AppDomain.CurrentDomain.BaseDirectory + @"/log/Log.txt");
- log.log("发模板消息前:"+token.ToString());
- if (_client != null){
- var response = _client.Execute(request);
- TemplateSendResponse resp = (TemplateSendResponse)response;
- Message msg = new Message(Guid.NewGuid(), MessageType.Request, content,
- DateTime.Now, "TemplateSend", resp.ErrorMessage);
- Message.Insert(msg);
- return msg;
- }
- else{
- string uri = string.Format(request.GetUrlFormat, token.access_token);
- var url = $"{new WXOptions().ApiUrl}{uri}";
- log.log("发模板消息前 url:" + url);
- var json = request.GetPostContentJson();
- log.log("发模板消息前 json:" + json);
- string responseContent = HttpHelper.HttpPost(url, json, "application/text").Result;
- TemplateSendResponse resp = JsonConvert.DeserializeObject<TemplateSendResponse>(responseContent);
- Message msg = new Message(Guid.NewGuid(), MessageType.Request, content,
- DateTime.Now, "TemplateSend",resp.ErrorCode+":"+ resp.ErrorMessage);
- Message.Insert(msg);
- return msg;
- }
- #endregion
- }
- return null;
- }
- }
- }
|