133 lines
4.4 KiB
C#
133 lines
4.4 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using AllBase;
|
|
|
|
namespace Work.Api
|
|
{
|
|
public class EncryptionCode
|
|
{
|
|
/// <summary>
|
|
/// 加密
|
|
/// </summary>
|
|
/// <param name="pid"></param>
|
|
/// <param name="sid"></param>
|
|
/// <param name="mid"></param>
|
|
/// <returns></returns>
|
|
public static string GetCode(long pid, int sid, int mid,out string code)
|
|
{
|
|
code = "";
|
|
if (sid == 1)
|
|
code = "tb-";
|
|
if (sid == 2)
|
|
code = "pd-";
|
|
if (sid == 3)
|
|
code = "al-";
|
|
if (sid == 4)
|
|
code = "jx-";
|
|
if (sid == 6)
|
|
code = "wd-";
|
|
code += pid;
|
|
if (pid == 0 || sid == 0 || mid == 0)
|
|
return "";
|
|
string url = BaseClass.LoginApiUrl + "api/encodex.php?mall_id=" + mid + "&pid=" + pid + "&site_id=" + sid;
|
|
string html = GetHtml.GetUrl(url);
|
|
if (!string.IsNullOrEmpty(html) && html.Length < 50)
|
|
return html;
|
|
|
|
code = "";
|
|
if (sid == 1)
|
|
code = "tb-";
|
|
if (sid == 2)
|
|
code = "pd-";
|
|
if (sid == 3)
|
|
code = "al-";
|
|
if (sid == 4)
|
|
code = "jx-";
|
|
if (sid == 6)
|
|
code = "wd-";
|
|
code += pid;
|
|
|
|
int randx = new Random(Guid.NewGuid().GetHashCode()).Next(100, 999);
|
|
int rmk = (mid % 27 + randx % 27) % 27;
|
|
int[] mainKey = new int[] { 6, 1, 5, 8, 4, 3, 6, 7, 0, 2, 9, 1, 2, 4, 7, 6, 5, 0, 1, 6, 8, 4, 6, 7, 9, 1 };
|
|
string news = new Random(Guid.NewGuid().GetHashCode()).Next(100, 999).ToString();
|
|
for (int i = 0; i < code.Length; i++)
|
|
{
|
|
int newValue = (int)code[i] - 40 + mainKey[i] * (i % 6) + rmk * (i % 5);
|
|
news += (char)newValue;
|
|
}
|
|
return "PBB" + EncodeBase64(Encoding.UTF8, news) + "?" + randx;
|
|
return code;
|
|
|
|
|
|
//int ridMain = new Random(Guid.NewGuid().GetHashCode()).Next(100, 999);
|
|
//int ridClient = (mid % ridMain) % 26;
|
|
|
|
//byte[] b = Encoding.Default.GetBytes(code);
|
|
//List<int> k = new List<int>();
|
|
//char[] ke = mid.ToString().ToCharArray();
|
|
//for (int i = 0; i < ke.Length; i++)
|
|
//{
|
|
// int j = int.Parse(ke[i].ToString());
|
|
// k.Add(j);
|
|
//}
|
|
//int y = 0;
|
|
//for (int i = 0; i < b.Length; i++)
|
|
//{
|
|
// int z = b[i] + k[y] * ridClient;
|
|
// b[i] = (byte)(z % 256);
|
|
// y++;
|
|
// if (y >= ke.Length)
|
|
// y = 0;
|
|
//}
|
|
//return "PBB" + Convert.ToBase64String(b) + "|" + ridMain;
|
|
}
|
|
public static string EncodeBase64(Encoding encode, string source)
|
|
{
|
|
byte[] bytes = encode.GetBytes(source);
|
|
try
|
|
{
|
|
string code = Convert.ToBase64String(bytes);
|
|
return code;
|
|
}
|
|
catch
|
|
{
|
|
return source;
|
|
}
|
|
}
|
|
|
|
|
|
public static void Test()
|
|
{
|
|
StringBuilder s = new StringBuilder();
|
|
for (int i = 0; i < 200; i++)
|
|
{
|
|
for (int sid = 1; sid < 4; sid++)
|
|
{
|
|
string code = "";
|
|
if (sid == 1)
|
|
code = "tb-";
|
|
if (sid == 2)
|
|
code = "pd-";
|
|
if (sid == 3)
|
|
code = "al-";
|
|
|
|
string mid = Randomx.GetNumber(Randomx.GetId(3, 8));
|
|
string pid = Randomx.GetNumber(Randomx.GetId(6,13));
|
|
code +=pid;
|
|
string url = "http://127.0.0.1:81/api/encodex.php?mall_id=" + mid + "&pid=" + pid + "&site_id=" + sid;
|
|
string html = GetHtml.Utf8(url);
|
|
url = "http://127.0.0.1:81/?obj=pinbaobao/decode&act=getx&mall_id=" + mid + "&encode=" + GetHtml.UrlEncodeUtf8(html);
|
|
string htmlx = GetHtml.Utf8(url);
|
|
s.AppendLine(code + "\t" + htmlx + "\t" + html);
|
|
}
|
|
}
|
|
string xxxx = s.ToString();
|
|
}
|
|
|
|
}
|
|
}
|