Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/#2809 change create pay sign input param #2810

Merged
merged 3 commits into from
Apr 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public void CreatePaySignTest()
TenPayV3_PrivateKey = privateKey
};

var result = TenPaySignHelper.CreatePaySign(timestamp, nonceStr, package, separcWeixinSetting);
var result = TenPaySignHelper.CreatePaySign(appId, timestamp, nonceStr, package, separcWeixinSetting);
Assert.IsNotNull(result);

var exceptedResult = "POmTZCzk7fj+FeSwbU4rNghygFOzwpoaQt9SBW8blDAPZCVJ7wVnDVisx6t1ryyBpB3NmOwiNaT+hHi7YthYZzr0kvL5kWKSnpssyWBofnjqbFWBSV8JaFx7Ia2qnsgdVYALisYjLBr+bj69YXuyWiBxYFx+JylH6wW4w55Rziatoa4rwrdlrpgE2yRTxDu9wSZ4VCdUYSMj2ctyAy2fOiCcP00VGjihJWGCXXjeVm2YQyFZXB7KqGPhncdHaFmJzIvL8SbWKSc36cUKSuHhZ5n+oZVU8Vf+lb/eJibzTWxBIAJbtQplKojG48ukd7QFtRUd3b2EkOjzmeJ26zMlfA==";
Expand All @@ -44,7 +44,7 @@ public void CreatePaySign_ByPrivateKeyTest()
var timestamp = "1414561699";
var nonceStr = "5K8264ILTKCH16CQ2502SI8ZNMTM67VS";

var result = TenPaySignHelper.CreatePaySign(timestamp, nonceStr, package, appId, privateKey);
var result = TenPaySignHelper.CreatePaySign(appId, timestamp, nonceStr, package, appId, privateKey);
Assert.IsNotNull(result);
Console.WriteLine(result);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,30 +85,31 @@ public static string CreateSign(string message, string privateKey = null)
/// <summary>
/// 获取调起支付所需的签名
/// </summary>
/// <param name="appId">传入的appId</param>
/// <param name="timeStamp">时间戳</param>
/// <param name="nonceStr">随机串</param>
/// <param name="package">格式:prepay_id={0}</param>
/// <param name="senparcWeixinSettingForTenpayV3">可为空 为空将从Senparc.Weixin.Config获取</param>
/// <returns></returns>
public static string CreatePaySign(string timeStamp, string nonceStr, string package, ISenparcWeixinSettingForTenpayV3 senparcWeixinSettingForTenpayV3 = null)
public static string CreatePaySign(string appId, string timeStamp, string nonceStr, string package, ISenparcWeixinSettingForTenpayV3 senparcWeixinSettingForTenpayV3 = null)
{
senparcWeixinSettingForTenpayV3 ??= Senparc.Weixin.Config.SenparcWeixinSetting.TenpayV3Setting;

var appId = senparcWeixinSettingForTenpayV3.TenPayV3_AppId;
var privateKey = senparcWeixinSettingForTenpayV3.TenPayV3_PrivateKey;

return CreatePaySign(timeStamp, nonceStr, package, appId, privateKey);
return CreatePaySign(appId, timeStamp, nonceStr, package, privateKey);
}

/// <summary>
/// 获取调起支付所需的签名
/// </summary>
/// <param name="appId">传入的appId</param>
/// <param name="timeStamp">时间戳</param>
/// <param name="nonceStr">随机串</param>
/// <param name="package">格式:prepay_id={0}</param>
/// <param name="privateKey">商户证书私钥</param>
/// <returns></returns>
public static string CreatePaySign(string timeStamp, string nonceStr, string package, string appId, string privateKey)
public static string CreatePaySign(string appId, string timeStamp, string nonceStr, string package, string privateKey)
{
string contentForSign = $"{appId}\n{timeStamp}\n{nonceStr}\n{package}\n";
return CreateSign(contentForSign, privateKey);
Expand Down Expand Up @@ -184,7 +185,7 @@ public static JsApiUiPackage GetJsApiUiPackage(string appId, string prepayId)
var timeStamp = TenPayV3Util.GetTimestamp();
var nonceStr = TenPayV3Util.GetNoncestr();
var prepayIdPackage = prepayId.Contains("prepay_id=") ? prepayId : string.Format("prepay_id={0}", prepayId);
var sign = TenPaySignHelper.CreatePaySign(timeStamp, nonceStr, prepayIdPackage);
var sign = TenPaySignHelper.CreatePaySign(appId, timeStamp, nonceStr, prepayIdPackage);

JsApiUiPackage jsApiUiPackage = new(appId, timeStamp, nonceStr, prepayIdPackage, sign);
return jsApiUiPackage;
Expand Down