[C#] 纯文本查看 复制代码
var ret = new JsonMsgRet<object>();
// 获取参数
var mobile = context.Request.Params["mobile"];
var time = context.Request.Params["time"];
var sign = InputHelper.CleanInputString(context.Request.Params["sign"]);
var source = InputHelper.GetInputInt(context.Request.Params["source"]);
Dictionary<string, string> param = new Dictionary<string, string>();
param.Add("mobile", mobile);
param.Add("time", time);
bool isBool = false;
if (source == 0)
{
//0 代表Android
param.Add("sign", sign);
param["sign"] = HttpUtility.UrlDecode(param["sign"], Encoding.UTF8);
//此类库借助支付宝AopSdk.dll Android这块直接使用[验签]的方法来验证。
isBool = AlipaySignature.RSACheckV2(param, AlipayAppConfig.Code_PUBLIC, AlipayAppConfig.CHARSET, "RSA2", false);
}
else
{
//1 代表IOS
param.Add("source", source.ToString());
//此类库借助支付宝RSAFromPkcs8.cs
var value = RSAFromPkcs8.RSADecrypt(sign, AlipayAppConfig.Code_PRIVATE_8, AlipayAppConfig.CHARSET);
if (AlipaySignature.GetSignContent(param) == value)
{
isBool = true;
}
}
if (!isBool)
{
ret.Status = MsgStatus.Failed;
ret.Content = "签名验证失败";
ret.ReturnValue = -1;
context.Response.Write(ret.ToJson());
return;
}