using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using JCSoft.WX.Framework.Api; using Microsoft.AspNetCore.Mvc; using JCSoft.WX.Framework.Models.ApiRequests; using JCSoft.WX.Framework.Models.ApiResponses; using ZcPeng.weixin.PublicAccount; using Microsoft.Extensions.Caching.Memory; using JCSoft.WX.Framework.Models; using Common.Wechat; namespace SupplierWeb.Controllers { [Route("api/SendTempleteMessage")] public class TempleteMessageController : BaseController { public TempleteMessageController(IMemoryCache cache, IApiClient client) : base(cache, client) { } //public JsonResult Get() //{ // ErrorMessage errorMessage; // long message = -1; // message = MassMessage.Send("gh_ab8f63a476a7", true, "group", MassMessageTypeEnum.text, "今晚打老虎", out errorMessage); // return Json(message); //} [HttpGet,Route("send")] public JsonResult Get() { var request = GetApiRequest(); var response = _client.Execute(request); return Json(response); } protected ApiRequest GetApiRequest() { Dictionary temp = new Dictionary(); TemplateDataProperty tmpdatap = new TemplateDataProperty(); tmpdatap.Value = "采购需求推送:"; tmpdatap.Color = "颜色#173177"; temp.Add("first", tmpdatap); tmpdatap.Value = "GoodsName"; tmpdatap.Color = "颜色#173177"; temp.Add("GoodsName", tmpdatap); tmpdatap.Value = "GoodsSpec"; tmpdatap.Color = "#173177"; temp.Add("GoodsSpec", tmpdatap); tmpdatap.Value = "StoreGapNum"; tmpdatap.Color = "#173177"; temp.Add("StoreGapNum", tmpdatap); tmpdatap.Value = "LastPrice"; tmpdatap.Color = "#173177"; temp.Add("LastPrice", tmpdatap); tmpdatap.Value = "EndTime"; tmpdatap.Color = "颜色#173177"; temp.Add("EndTime", tmpdatap); tmpdatap.Value = "请登陆我们的系统填写可供货数量:http://localhost:8000 账户:密码:如果未绑定请先绑定手机号"; 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, "获取许可令牌失败。"); } return new TemplateSendRequest { AccessToken = token.access_token, ToUser = "os3Qpt_OfJ3SIYCsYmDz89xwk_94", TemplateID = "R4bsIWvHkEz5cfQsa1sa5EVDCvUynY5FrxvuevUAcjE",//SnuX3WGoLBBEUs9wnwyqur0ocdypUk2euX45BIj9JKk TopColor = "#FF0000", Url = "http://119.27.191.247/web/supplymobile/bindphone", Data = temp, }; } } }