152 lines
7.3 KiB
C#
152 lines
7.3 KiB
C#
using System;
|
||
using System.Collections.Generic;
|
||
using System.Linq;
|
||
using System.Text;
|
||
using System.Text.RegularExpressions;
|
||
|
||
namespace EShangPayTest
|
||
{
|
||
internal class Program
|
||
{
|
||
static void Main(string[] args)
|
||
{
|
||
string memberECode = "20330422360451504259148";
|
||
Console.WriteLine(ECodeToDecrypt(memberECode.Substring(4, 9), int.Parse(memberECode.Substring(memberECode.Length - 2, 1))));
|
||
////tzlnrm918d
|
||
////生成移动支付交易参数对象
|
||
//libESPay.PayUtils.MobilePayConfig.PayMerchant payMerchant = new libESPay.PayUtils.MobilePayConfig.PayMerchant
|
||
//{
|
||
// MerchantAPPID = "",
|
||
// MerchantCode = "tuqprka1a7",
|
||
// MerchantKey = "",
|
||
// MerchantPosCode = "",
|
||
// MerchantShopCode = "",
|
||
// MobilePayOperatorURL = "https://apisvbak2.ke51.cn",
|
||
// MobilePayProxyURL = "http://10.103.1.8:17080/DataTransferService/Service.asmx"
|
||
//};
|
||
//libESPay.ESPayService.ESTScanPay(libESPay.PayUtils.MobilePayOperators.kwypay, payMerchant, "132989145270352427", "348888012001999920221122102200", "0.01", "", false);
|
||
|
||
Dictionary<string, string> _ApiDictionary = new Dictionary<string, string>
|
||
{
|
||
{ "date", "2023-01-16,2023-01-16" },//查询开始时间
|
||
{ "page", "1" },
|
||
{ "page_size", "50" },
|
||
{ "nonce_str", "0" },
|
||
{ "bind_code", "tuqprka1a7" },//商户编号
|
||
{ "openid", "1z7n0lp0nsi8o0dd5o74lgrhs1575k" },//客无忧平台对接的OPENID
|
||
{
|
||
"time_stamp",Convert.ToInt32((DateTime.Now - TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1))).TotalSeconds).ToString()
|
||
}//时间戳
|
||
};
|
||
//交易参数签名
|
||
_ApiDictionary.Add("sign", libESPay.KwyPay.KwyPayAPI.ApiParamSign(_ApiDictionary, "w0j23q2m69po13syyd6pj6a11o64f2r13bj"));
|
||
//拼接交易请求参数
|
||
string str_PostData = _ApiDictionary.Select(pair => $"{pair.Key}={pair.Value}")
|
||
.DefaultIfEmpty("").Aggregate((a, b) => $"{a}&{b}");
|
||
string str_Result = libESPay.PayUtils.ESHttpClient.HttpUrlPost(str_PostData, "https://apisvbak2.ke51.cn/Payapi/Ys/royalty", "application/x-www-form-urlencoded", 5);
|
||
|
||
//Dictionary<string, string> _ApiDictionary = new Dictionary<string, string>
|
||
//{
|
||
// { "mch_id", "39860634" },//主账商户号
|
||
// { "to_mch_id", "39844222" },//分账商户号
|
||
// { "mch_type", "盛付通商户" },//商户类型
|
||
// { "royalty_rate", "2300" },//分账比例
|
||
// { "bind_code", "tuqprka1a7" },//商户编号
|
||
// { "nonce_str", "0" },
|
||
// { "openid", "1z7n0lp0nsi8o0dd5o74lgrhs1575k" },//客无忧平台对接的OPENID
|
||
// {
|
||
// "time_stamp",Convert.ToInt32((DateTime.Now - TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1))).TotalSeconds).ToString()
|
||
// }//时间戳
|
||
//};
|
||
////交易参数签名
|
||
//_ApiDictionary.Add("sign", libESPay.KwyPay.KwyPayAPI.ApiParamSign(_ApiDictionary, "w0j23q2m69po13syyd6pj6a11o64f2r13bj"));
|
||
////拼接交易请求参数
|
||
//string str_PostData = _ApiDictionary.Select(pair => $"{pair.Key}={pair.Value}")
|
||
// .DefaultIfEmpty("").Aggregate((a, b) => $"{a}&{b}");
|
||
//string str_Result = libESPay.PayUtils.ESHttpClient.HttpUrlPost(str_PostData, "https://apisvbak2.ke51.cn/Payapi/Ys/setRoyaltyRate", "application/x-www-form-urlencoded", 5);
|
||
Console.WriteLine(str_Result);
|
||
Console.ReadKey();
|
||
}
|
||
#region 方法 -> 电子码信息加解密
|
||
/// <summary>
|
||
/// 数字串加密
|
||
/// </summary>
|
||
/// <param name="sourceECode">原数字串</param>
|
||
/// <param name="priKey">
|
||
/// 密钥(一位数字)
|
||
/// <para>取值范围:0-9</para>
|
||
/// </param>
|
||
/// <returns>
|
||
/// <para>成功:返回加密后的数字串</para>
|
||
/// <para>失败:返回空白字符</para>
|
||
/// </returns>
|
||
public static string ECodeToEncrypt(string sourceECode, int priKey)
|
||
{
|
||
//待加密的数字串或密钥非数字时,返回空白字符
|
||
if (!Regex.IsMatch(sourceECode, @"^[0-9]*$") || !Regex.IsMatch(priKey.ToString(), @"^[0-9]$"))
|
||
{
|
||
return string.Empty;
|
||
}
|
||
//密钥为0时直接返回原数字串
|
||
if (priKey == 0) return sourceECode;
|
||
//开始加密
|
||
string _EncryptCode = "";
|
||
char[] _Temp = sourceECode.ToCharArray();
|
||
for (int i = 0; i < _Temp.Length; i++)
|
||
{
|
||
//当前数字位数奇偶位与密钥奇偶数一致时,当前位数字加上密钥
|
||
int _TempCode = int.Parse(_Temp[i].ToString()) + ((i + 1) % 2 != priKey % 2 ? 0 : priKey);
|
||
//当加密后数字大于等于10时,取个位
|
||
if (_TempCode > 9)
|
||
{
|
||
_TempCode -= 10;
|
||
}
|
||
_EncryptCode += _TempCode;
|
||
}
|
||
//加密后数字串与原数字串不一致时,加密成功返回加密后数字串,否则返回空白字符
|
||
return _EncryptCode != sourceECode ? _EncryptCode : string.Empty;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 数字串解密
|
||
/// </summary>
|
||
/// <param name="sourceECode">加密的数字串</param>
|
||
/// <param name="priKey">
|
||
/// 密钥(一位数字)
|
||
/// <para>取值范围:0-9</para>
|
||
/// </param>
|
||
/// <returns>
|
||
/// <para>成功:返回解密后的数字串</para>
|
||
/// <para>失败:返回空白字符</para>
|
||
/// </returns>
|
||
public static string ECodeToDecrypt(string sourceECode, int priKey)
|
||
{
|
||
//待解密的数字串非数字或密钥范围错误时,返回空白字符
|
||
if (!Regex.IsMatch(sourceECode, @"^[0-9]*$") || !Regex.IsMatch(priKey.ToString(), @"^[0-9]$"))
|
||
{
|
||
return string.Empty;
|
||
}
|
||
//密钥为0时直接返回原数字串
|
||
if (priKey == 0) return sourceECode;
|
||
//开始解密
|
||
string _DecryptCode = "";
|
||
char[] _Temp = sourceECode.ToCharArray();
|
||
for (int i = 0; i < _Temp.Length; i++)
|
||
{
|
||
//当前数字位数奇偶位与密钥奇偶数一致时,当前位数字加上密钥
|
||
int _TempCode = int.Parse(_Temp[i].ToString());
|
||
//当加密后的数字小于密钥时,数字加10
|
||
if (_TempCode < priKey)
|
||
{
|
||
_TempCode += (i + 1) % 2 != priKey % 2 ? 0 : 10;
|
||
}
|
||
//当前数字位数奇偶位与密钥奇偶数一致时,当前位数字减去密钥
|
||
_DecryptCode += _TempCode - ((i + 1) % 2 != priKey % 2 ? 0 : priKey);
|
||
}
|
||
//解密后数字串与传入的加密数字串不一致时,解密成功返回解密后数字串,否则返回空白字符
|
||
return _DecryptCode != sourceECode ? _DecryptCode : string.Empty;
|
||
}
|
||
#endregion
|
||
}
|
||
}
|