TempleteMessageController.cs 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Threading.Tasks;
  5. using JCSoft.WX.Framework.Api;
  6. using Microsoft.AspNetCore.Mvc;
  7. using JCSoft.WX.Framework.Models.ApiRequests;
  8. using JCSoft.WX.Framework.Models.ApiResponses;
  9. using ZcPeng.weixin.PublicAccount;
  10. using Microsoft.Extensions.Caching.Memory;
  11. using JCSoft.WX.Framework.Models;
  12. using Common.Wechat;
  13. namespace SupplierWeb.Controllers
  14. {
  15. [Route("api/SendTempleteMessage")]
  16. public class TempleteMessageController : BaseController
  17. {
  18. public TempleteMessageController(IMemoryCache cache, IApiClient client) : base(cache, client)
  19. {
  20. }
  21. //public JsonResult Get()
  22. //{
  23. // ErrorMessage errorMessage;
  24. // long message = -1;
  25. // message = MassMessage.Send("gh_ab8f63a476a7", true, "group", MassMessageTypeEnum.text, "今晚打老虎", out errorMessage);
  26. // return Json(message);
  27. //}
  28. [HttpGet,Route("send")]
  29. public JsonResult Get()
  30. {
  31. var request = GetApiRequest();
  32. var response = _client.Execute(request);
  33. return Json(response);
  34. }
  35. protected ApiRequest<TemplateSendResponse> GetApiRequest()
  36. {
  37. Dictionary<string, TemplateDataProperty> temp = new Dictionary<string, TemplateDataProperty>();
  38. TemplateDataProperty tmpdatap = new TemplateDataProperty();
  39. tmpdatap.Value = "采购需求推送:";
  40. tmpdatap.Color = "颜色#173177";
  41. temp.Add("first", tmpdatap);
  42. tmpdatap.Value = "GoodsName";
  43. tmpdatap.Color = "颜色#173177";
  44. temp.Add("GoodsName", tmpdatap);
  45. tmpdatap.Value = "GoodsSpec";
  46. tmpdatap.Color = "#173177";
  47. temp.Add("GoodsSpec", tmpdatap);
  48. tmpdatap.Value = "StoreGapNum";
  49. tmpdatap.Color = "#173177";
  50. temp.Add("StoreGapNum", tmpdatap);
  51. tmpdatap.Value = "LastPrice";
  52. tmpdatap.Color = "#173177";
  53. temp.Add("LastPrice", tmpdatap);
  54. tmpdatap.Value = "EndTime";
  55. tmpdatap.Color = "颜色#173177";
  56. temp.Add("EndTime", tmpdatap);
  57. tmpdatap.Value = "请登陆我们的系统填写可供货数量:http://localhost:8000 账户:密码:如果未绑定请先绑定手机号";
  58. tmpdatap.Color = "颜色#173177";
  59. temp.Add("remark", tmpdatap);
  60. //加入测试公众号
  61. AccountInfo account = new AccountInfo(Config.WeChatAppName, Config.WeChatAppKey, Config.WeChatAppSecret, null, null);
  62. AccountInfoCollection.SetAccountInfo(account);
  63. //加入正式公众号
  64. //AccountInfoCollection.SetAccountInfo(new AccountInfo("YourId2", "AppId", "AppSecret", "Token", "EncodingAesKey", "非測試"));
  65. ZcPeng.weixin.PublicAccount.AccessToken token = ZcPeng.weixin.PublicAccount.AccessToken.Get(Config.WeChatAppName);
  66. if (token == null)
  67. {
  68. ErrorMessage errorMessage = new ErrorMessage(ErrorMessage.ExceptionCode, "获取许可令牌失败。");
  69. }
  70. return new TemplateSendRequest
  71. {
  72. AccessToken = token.access_token,
  73. ToUser = "os3Qpt_OfJ3SIYCsYmDz89xwk_94",
  74. TemplateID = "R4bsIWvHkEz5cfQsa1sa5EVDCvUynY5FrxvuevUAcjE",//SnuX3WGoLBBEUs9wnwyqur0ocdypUk2euX45BIj9JKk
  75. TopColor = "#FF0000",
  76. Url = "http://119.27.191.247/web/supplymobile/bindphone",
  77. Data = temp,
  78. };
  79. }
  80. }
  81. }