|
|
@@ -28,6 +28,7 @@ namespace CallCenterAPI.WechatSDK
|
|
28
|
28
|
public static string WechatMchid;
|
|
29
|
29
|
public static string WechatKey;
|
|
30
|
30
|
public static string WechatPath;
|
|
|
31
|
+ public static string WechatClientIp;
|
|
31
|
32
|
|
|
32
|
33
|
public static string CommonToken;//Common的Token
|
|
33
|
34
|
public static DateTime GetCommonTokenDate;//获取CommonToken的时间
|
|
|
@@ -40,6 +41,7 @@ namespace CallCenterAPI.WechatSDK
|
|
40
|
41
|
WechatMchid= Configs.GetValue("WechatMchid");
|
|
41
|
42
|
WechatKey = Configs.GetValue("WechatKey");
|
|
42
|
43
|
WechatPath = Configs.GetValue("WechatPath");
|
|
|
44
|
+ WechatClientIp = Configs.GetValue("WechatClientIp");
|
|
43
|
45
|
}
|
|
44
|
46
|
|
|
45
|
47
|
/// <summary>
|
|
|
@@ -49,7 +51,6 @@ namespace CallCenterAPI.WechatSDK
|
|
49
|
51
|
/// <returns></returns>
|
|
50
|
52
|
public static WxLoginDto GetOpenId(WxLoginDto wxLoginDto)
|
|
51
|
53
|
{
|
|
52
|
|
-
|
|
53
|
54
|
if (string.IsNullOrWhiteSpace(wxLoginDto.Code))
|
|
54
|
55
|
{
|
|
55
|
56
|
var url = OAuthApi.GetAuthorizeUrl(AppId, wxLoginDto.RedirectUrl, "qwertyuidfghjkl", OAuthScope.snsapi_base);
|
|
|
@@ -246,10 +247,11 @@ namespace CallCenterAPI.WechatSDK
|
|
246
|
247
|
#endregion
|
|
247
|
248
|
|
|
248
|
249
|
#region 企业向用户发红包
|
|
249
|
|
- public static bool TenPay(decimal amount,string clientip,string openid)
|
|
|
250
|
+ public static bool TenPay(decimal amount,string openid)
|
|
250
|
251
|
{
|
|
251
|
252
|
#region 发送红包
|
|
252
|
253
|
bool fals = false; //记录发送红包是否成功
|
|
|
254
|
+ string msg = "";
|
|
253
|
255
|
string xmlResult = null; //现金红包接口返回的xml
|
|
254
|
256
|
string certPath = null; //证书在服务器的物理位置
|
|
255
|
257
|
string data = null; //调用现金红包接口需要的数据
|
|
|
@@ -260,11 +262,11 @@ namespace CallCenterAPI.WechatSDK
|
|
260
|
262
|
//初始化
|
|
261
|
263
|
packageReqHandler.Init();
|
|
262
|
264
|
string nonceStr = TenPayV3Util.GetNoncestr(); //时间戳
|
|
263
|
|
- string sign = packageReqHandler.CreateMd5Sign("key", WechatKey);
|
|
|
265
|
+
|
|
264
|
266
|
//设置package订单参数
|
|
265
|
267
|
|
|
266
|
268
|
packageReqHandler.SetParameter("nonce_str", nonceStr); //随机字符串,不长于32位
|
|
267
|
|
- packageReqHandler.SetParameter("sign", sign); //签名:生成签名方式查看签名算法
|
|
|
269
|
+
|
|
268
|
270
|
|
|
269
|
271
|
var r = new Random(Guid.NewGuid().GetHashCode());//随机数
|
|
270
|
272
|
var dd = DateTime.Now.ToString("yyyymmdd");//日期yyyymmdd
|
|
|
@@ -278,10 +280,12 @@ namespace CallCenterAPI.WechatSDK
|
|
278
|
280
|
packageReqHandler.SetParameter("total_num", "1");//红包发放总人数
|
|
279
|
281
|
|
|
280
|
282
|
packageReqHandler.SetParameter("wishing", "测试红包"); //红包祝福语
|
|
281
|
|
- packageReqHandler.SetParameter("client_ip", clientip);//Ip地址
|
|
|
283
|
+ packageReqHandler.SetParameter("client_ip", WechatClientIp);//Ip地址
|
|
282
|
284
|
packageReqHandler.SetParameter("act_name", "测试红包"); //活动名称
|
|
283
|
285
|
packageReqHandler.SetParameter("remark", "测试红包"); //备注
|
|
284
|
286
|
|
|
|
287
|
+ string sign = packageReqHandler.CreateMd5Sign("key", WechatKey);
|
|
|
288
|
+ packageReqHandler.SetParameter("sign", sign); //签名:生成签名方式查看签名算法
|
|
285
|
289
|
|
|
286
|
290
|
data = packageReqHandler.ParseXML();
|
|
287
|
291
|
certPath = WechatPath;
|
|
|
@@ -295,10 +299,19 @@ namespace CallCenterAPI.WechatSDK
|
|
295
|
299
|
{
|
|
296
|
300
|
fals = true;
|
|
297
|
301
|
}
|
|
|
302
|
+ else
|
|
|
303
|
+ {
|
|
|
304
|
+ msg = res.Element("xml").Element("err_code_des").Value;
|
|
|
305
|
+ }
|
|
|
306
|
+ }
|
|
|
307
|
+ else
|
|
|
308
|
+ {
|
|
|
309
|
+ msg = res.Element("xml").Element("return_msg").Value;
|
|
298
|
310
|
}
|
|
299
|
311
|
}
|
|
300
|
312
|
catch (Exception exception)
|
|
301
|
313
|
{
|
|
|
314
|
+ msg = exception.Message;
|
|
302
|
315
|
}
|
|
303
|
316
|
#endregion
|
|
304
|
317
|
return fals;
|
|
|
@@ -314,11 +327,11 @@ namespace CallCenterAPI.WechatSDK
|
|
314
|
327
|
/// <returns></returns>
|
|
315
|
328
|
public static string Sendredpack(string data, string certPassword, string certPath, int timeOut = Config.TIME_OUT)
|
|
316
|
329
|
{
|
|
317
|
|
- var urlFormat = "https://api.mch.weixin.qq.com/mmpaymkttransfers/hbpreorder";
|
|
318
|
|
- string cert = certPath;
|
|
|
330
|
+ var urlFormat = "https://api.mch.weixin.qq.com/mmpaymkttransfers/sendredpack";
|
|
|
331
|
+ string cert = HttpContext.Current.Request.PhysicalApplicationPath+ certPath;
|
|
319
|
332
|
|
|
320
|
333
|
ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(CheckValidationResult);
|
|
321
|
|
- X509Certificate2 cer = new X509Certificate2(cert, certPassword, X509KeyStorageFlags.PersistKeySet | X509KeyStorageFlags.MachineKeySet);
|
|
|
334
|
+ X509Certificate2 cer = new X509Certificate2(cert, certPassword);
|
|
322
|
335
|
|
|
323
|
336
|
var formDataBytes = data == null ? new byte[0] : Encoding.UTF8.GetBytes(data);
|
|
324
|
337
|
MemoryStream ms = new MemoryStream();
|