API接入

代码描述:基于C#的千游互娱API服务接口调用示例

关联数据:商品查询API服务

接口地址:

http://api.qianyou.cn:11140/UserGoodsController/userQueryGoodsInfo


 qianyou

     

 2017-10-16 10:04

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135

using Newtonsoft.Json;

using System;

using System.Collections.Generic;

using System.IO;

using System.Net;

using System.Security.Cryptography;

using System.Text;

 

namespace Qianyou.goods

{

public class QueryProduct

{

//请求网址

private static readonly string REQUESTURL = "http://api.qianyou.cn:11140/UserGoodsController/userQueryGoodsInfo";

static void Main(string[] args)

{

GetGoodsInfoDemo();

}

public static void GetGoodsInfoDemo()

{

var url = REQUESTURL;

//加密原串

StringBuilder source = new StringBuilder();

source.Append("userNo").Append(userNo);

source.Append(key);

var sign = Md5Encrypt(source.ToString());//加密

//请求参数

StringBuilder data = new StringBuilder();

data.Append("userNo=").Append(userNo);

data.Append("&sign=").Append(sign);

try

{

var resposne = HttpPost(url, data.ToString());

if(resposne.Contains("code"))

{

var result = JsonConvert.DeserializeObject<GetGoodInfoResponse>(resposne);

}

}

catch (Exception ex)

{

 

throw;

}

}

public static string Md5Encrypt(string input)

{

return Md5Encrypt(input, Encoding.UTF8);

}

 

/// <summary>

/// 对字符串进行MD5加密

/// </summary>

/// <param name="input"></param>

/// <param name="enc"></param>

/// <returns></returns>

public static string Md5Encrypt(string input, Encoding enc)

{

var md5 = new MD5CryptoServiceProvider();

var buffer = md5.ComputeHash(enc.GetBytes(input));

var builder = new StringBuilder(32);

foreach (var t in buffer)

{

builder.Append(t.ToString("x").PadLeft(2, '0'));

}

return builder.ToString();

}

/// <summary>

/// post请求方法 (仅供参考)

/// </summary>

/// <param name="Url"></param>

/// <param name="postDataStr"></param>

/// <returns></returns>

private static string HttpPost(string Url, string postDataStr)

{

HttpWebRequest request = (HttpWebRequest)WebRequest.Create(Url);

request.Method = "POST";

request.ContentType = "application/x-www-form-urlencoded";

request.ContentLength = Encoding.UTF8.GetByteCount(postDataStr);

Stream myRequestStream = request.GetRequestStream();

StreamWriter myStreamWriter = new StreamWriter(myRequestStream, Encoding.GetEncoding("gb2312"));

myStreamWriter.Write(postDataStr);

myStreamWriter.Close();

HttpWebResponse response = (HttpWebResponse)request.GetResponse();

Stream myResponseStream = response.GetResponseStream();

StreamReader myStreamReader = new StreamReader(myResponseStream, Encoding.GetEncoding("utf-8"));

string retString = myStreamReader.ReadToEnd();

myStreamReader.Close();

myResponseStream.Close();

return retString;

}

}

public class GetGoodInfoResponse

{

public List<QyGood> Result { get; set; }

public string Msg { get; set; }

public long Code { get; set; }

}

public class GameWaysItem

{

public string WayName { get; set; }

public string WayCode { get; set; }

}

public class GameServersItem

{

public string ServerName { get; set; }

public string ServerCode { get; set; }

}

public class GameAreasItem

{

public string AreaName { get; set; }

public string AreaCode { get; set; }

public List<GameServersItem> GameServers { get; set; }

}

 

public class GamesItem

{

public string GameName { get; set; }

public string GameCode { get; set; }

public List<GameAreasItem> GameAreas { get; set; }

public List<GameWaysItem> GameWays { get; set; }

}

 

public class QyGood

{

public long GoodsId { get; set; }

public string GoodsName { get; set; }

public long GoodsType { get; set; }

public long FaceValue { get; set; }

public string Amount { get; set; }

public string AccountType { get; set; }

public long AccountTypeNo { get; set; }

public string Province { get; set; }

public List<GamesItem> Games { get; set; }

}

}

千游互娱平台-游戏点卡充值 视频会员直充 卡密购买 API接口