diff --git a/B3WeChat/B3WeChat.csproj b/B3WeChat/B3WeChat.csproj
index a7a2bad..b9126cc 100644
--- a/B3WeChat/B3WeChat.csproj
+++ b/B3WeChat/B3WeChat.csproj
@@ -122,6 +122,7 @@
+
diff --git a/B3WeChat/Entities/GetTicketResponse.cs b/B3WeChat/Entities/GetTicketResponse.cs
new file mode 100644
index 0000000..9677638
--- /dev/null
+++ b/B3WeChat/Entities/GetTicketResponse.cs
@@ -0,0 +1,14 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace BWP.B3WeChat.Entities
+{
+ public class GetTicketResponse:WeChatResponseBase
+ {
+ public string ticket { get; set; }
+
+ public int expires_in { get; set; }
+ }
+}
diff --git a/B3WeChat/Rpcs/WeChatUserRpc.cs b/B3WeChat/Rpcs/WeChatUserRpc.cs
index d30e4d1..95db329 100644
--- a/B3WeChat/Rpcs/WeChatUserRpc.cs
+++ b/B3WeChat/Rpcs/WeChatUserRpc.cs
@@ -1,6 +1,7 @@
using BWP.B3WeChat.BL;
using BWP.B3WeChat.BO;
using BWP.B3WeChat.BO.NamedValueTemplate;
+using BWP.B3WeChat.Utils;
using Forks.EnterpriseServices.DomainObjects2;
using Forks.EnterpriseServices.DomainObjects2.DQuery;
using Forks.EnterpriseServices.JsonRpc;
@@ -87,5 +88,10 @@ namespace BWP.B3WeChat.Rpcs
}
+ [Rpc]
+ public static string GetJsApiSignature(string noncestr, string timestamp, string url)
+ {
+ return InOutMessageUtil.GetJsApiSignature(noncestr, timestamp, url);
+ }
}
}
diff --git a/B3WeChat/Utils/InOutMessageUtil.cs b/B3WeChat/Utils/InOutMessageUtil.cs
index 4483f1f..0680e80 100644
--- a/B3WeChat/Utils/InOutMessageUtil.cs
+++ b/B3WeChat/Utils/InOutMessageUtil.cs
@@ -2,6 +2,7 @@
using BWP.B3WeChat.BO;
using BWP.B3WeChat.Entities;
using Forks.Utils;
+using Forks.Utils.Caching;
using System;
using System.Collections.Generic;
using System.IO;
@@ -140,6 +141,37 @@ namespace BWP.B3WeChat.Utils
GetRequest(url);
}
+
+ static DateTime? ticketExpiredTime;
+
+ static string GetJsApiTicket()
+ {
+ var time = DateTime.Now;
+ if (ticketExpiredTime == null || ticketExpiredTime.Value > time)
+ {
+ //过期时间是2小时,不过这里小一些,避免边界问题
+ ticketExpiredTime = time.Add(new TimeSpan(1, 30, 30));
+ }
+
+ var key = string.Format("{0}_GetJsApiTicket_{1}", TOKEN, ticketExpiredTime.Value.Ticks);
+
+ return CacheManager.GetOrSet(key, (args) =>
+ {
+ var url = string.Format("https://api.weixin.qq.com/cgi-bin/ticket/getticket?access_token={0}&type=jsapi", TOKEN);
+ var res = GetRequest(url);
+ return res.ticket;
+ });
+
+ }
+
+ public static string GetJsApiSignature(string noncestr, string timestamp, string url)
+ {
+ var origin = string.Format("jsapi_ticket={0}&=noncestr{1}×tamp={2}&url={3}", GetJsApiTicket(),noncestr, timestamp, url);
+ return FormsAuthentication.HashPasswordForStoringInConfigFile(origin, "SHA1").ToLower();
+ }
+
+
+
public static List GetOpenIDList()
{