-
Notifications
You must be signed in to change notification settings - Fork 4.4k
/
Copy pathTemplateMessageService.cs
74 lines (63 loc) · 3.53 KB
/
TemplateMessageService.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
using Senparc.CO2NET.Cache;
using Senparc.Weixin.Sample.CommonService.TemplateMessage.WxOpen;
using Senparc.Weixin.TenPay.V3;
using Senparc.Weixin.WxOpen.Containers;
using System;
using System.Threading.Tasks;
namespace Senparc.Weixin.Sample.CommonService
{
public class TemplateMessageService
{
[Obsolete("2020年01月10日起,新发布的小程序将不能使用模板消息,请迁移至“订阅消息”功能。")]
public async Task<SessionBag> RunTemplateTestAsync(string wxOpenAppId, string sessionId, string formId)
{
var sessionBag = await SessionContainer.GetSessionAsync(sessionId);
//var openId = sessionBag != null ? sessionBag.OpenId : "用户未正确登陆";
//string title = null;
//decimal price = 1;//单位:分,实际使用过程中,通过数据库获取订单并读取
//string productName = null;
//string orderNumber = null;
//if (formId.StartsWith("prepay_id="))
//{
// formId = formId.Replace("prepay_id=", "");
// title = "这是来自小程序支付的模板消息(仅测试接收,数据不一定真实)";
//
// var cacheStrategy = CacheStrategyFactory.GetObjectCacheStrategyInstance();
// var unifiedorderRequestData = await cacheStrategy.GetAsync<TenPayV3UnifiedorderRequestData>($"WxOpenUnifiedorderRequestData-{openId}");//获取订单请求信息缓存
// var unifedorderResult = await cacheStrategy.GetAsync<UnifiedorderResult>($"WxOpenUnifiedorderResultData-{openId}");//获取订单信息缓存
// if (unifedorderResult != null && formId == unifedorderResult.prepay_id)
// {
// price = unifiedorderRequestData.TotalFee;
// productName = unifiedorderRequestData.Body + "/缓存获取 prepay_id 成功";
// orderNumber = unifiedorderRequestData.OutTradeNo;
// }
// else//DPBMARK_END
// {
// productName = "缓存获取 prepay_id 失败";
// orderNumber = "1234567890";
// }
// productName += " | 注意:这条消息是从小程序发起的!仅作为UI上支付成功的演示!不能确定支付真实成功! | prepay_id:";
// productName += unifedorderResult.prepay_id;
//}
//else
//{
// title = "在线购买(仅测试小程序接收模板消息,数据不一定真实)";
// productName = "商品名称-模板消息测试";
// orderNumber = "9876543210";
//}
//var data = new WxOpenTemplateMessage_PaySuccessNotice(title, SystemTime.Now, productName, orderNumber, price,
// "400-031-8816", "https://sdk.senparc.weixin.com");
//await Senparc.Weixin.WxOpen.AdvancedAPIs
// .Template.TemplateApi
// .SendTemplateMessageAsync(
// wxOpenAppId, openId, data.TemplateId, data, formId, "pages/index/index", "图书", "#fff00");
return sessionBag;
}
[Obsolete("建议使用 RunTemplateTestAsync 方法")]
public SessionBag RunTemplateTest(string wxOpenAppId, string sessionId, string formId)
{
var sessionBag = RunTemplateTestAsync(wxOpenAppId, sessionId, formId).ConfigureAwait(false).GetAwaiter().GetResult();
return sessionBag;
}
}
}