1
|
using Newtonsoft.Json;
|
2
|
using Newtonsoft.Json.Linq;
|
3
|
using System;
|
4
|
using System.Collections.Generic;
|
5
|
using System.IO;
|
6
|
using System.Linq;
|
7
|
using System.Net;
|
8
|
using System.Security.Cryptography;
|
9
|
using System.Text;
|
10
|
using System.Text.RegularExpressions;
|
11
|
using System.Web;
|
12
|
using System.Web.UI;
|
13
|
using System.Web.UI.WebControls;
|
14
|
|
15
|
public class Test
|
16
|
{
|
17
|
|
18
|
#region 第一步:定义加签方法
|
19
|
|
20
|
/// <summary>
|
21
|
/// 取得传入数据的签名
|
22
|
/// </summary>
|
23
|
/// <param name="data"></param>
|
24
|
/// <returns></returns>
|
25
|
public String getSignCNT(JObject data)
|
26
|
{
|
27
|
String controller = "VehicleInsurance3";
|
28
|
String method = "SaveNewInsYBT";
|
29
|
String signMethod = "MD5";
|
30
|
|
31
|
if (data["orgID"] == null || "".Equals(data["orgID"].ToString()))
|
32
|
{
|
33
|
throw new Exception("未找到商户代码,无法进行签名验证。");
|
34
|
}
|
35
|
String orgID = data["orgID"].ToString();
|
36
|
|
37
|
// 取得所有参数
|
38
|
SortedList<String, String> ncoll = new SortedList<String, String>();
|
39
|
foreach (var item in data)
|
40
|
{
|
41
|
if ("signature".Equals(item.Key)
|
42
|
|| "method".Equals(item.Key)
|
43
|
|| "signMethod".Equals(item.Key))
|
44
|
{
|
45
|
continue;
|
46
|
}
|
47
|
else
|
48
|
{
|
49
|
if (item.Key.ToLower().Contains("date")
|
50
|
&& !String.IsNullOrEmpty(item.Value.ToString()) && "MD5L".Equals(signMethod))
|
51
|
{
|
52
|
ncoll.Add(item.Key, item.Value.ToObject<DateTime>().Ticks.ToString());
|
53
|
}
|
54
|
else if (item.Key.ToLower().Contains("datel")
|
55
|
&& !String.IsNullOrEmpty(item.Value.ToString()) && "MD5".Equals(signMethod))
|
56
|
{
|
57
|
ncoll.Add(item.Key, item.Value.ToObject<DateTime>().ToString("yyyy-MM-dd HH:mm:ss"));
|
58
|
}
|
59
|
else
|
60
|
{
|
61
|
ncoll.Add(item.Key, item.Value.ToString());
|
62
|
}
|
63
|
}
|
64
|
}
|
65
|
|
66
|
// 取得排序后的POST字符串
|
67
|
var sbPostSort = new StringBuilder();
|
68
|
foreach (var item in ncoll)
|
69
|
{
|
70
|
sbPostSort.Append('&');
|
71
|
sbPostSort.Append(item.Key);
|
72
|
sbPostSort.Append('=');
|
73
|
sbPostSort.Append(item.Value);
|
74
|
}
|
75
|
|
76
|
|
77
|
String postString = sbPostSort.ToString(1, sbPostSort.Length - 1);
|
78
|
String postStringSignAll = String.Format("{0}|{1}|{2}|{3}", controller, method, postString, MD5Encrypt(orgID + "MD5", 32));
|
79
|
|
80
|
String signature = "";
|
81
|
signature = MD5Encrypt(postStringSignAll, 32);
|
82
|
|
83
|
return signature;
|
84
|
}
|
85
|
|
86
|
/// <summary>
|
87
|
/// MD5加密,和动网上的16/32位MD5加密结果相同
|
88
|
/// </summary>
|
89
|
/// <param name="strSource">待加密字串</param>
|
90
|
/// <param name="length">16或32值之一,其它则采用.net默认MD5加密算法</param>
|
91
|
/// <returns>加密后的字串</returns>
|
92
|
public static string MD5Encrypt(string strSource, int length)
|
93
|
{
|
94
|
byte[] bytes = Encoding.UTF8.GetBytes(strSource);
|
95
|
byte[] hashValue = ((System.Security.Cryptography.HashAlgorithm)
|
96
|
System.Security.Cryptography.CryptoConfig.CreateFromName("MD5")).ComputeHash(bytes);
|
97
|
StringBuilder sb = new StringBuilder();
|
98
|
switch (length)
|
99
|
{
|
100
|
case 16:
|
101
|
for (int i = 4; i < 12; i++)
|
102
|
sb.Append(hashValue[i].ToString("x2"));
|
103
|
break;
|
104
|
case 32:
|
105
|
for (int i = 0; i < 16; i++)
|
106
|
{
|
107
|
sb.Append(hashValue[i].ToString("x2"));
|
108
|
}
|
109
|
break;
|
110
|
default:
|
111
|
for (int i = 0; i < hashValue.Length; i++)
|
112
|
{
|
113
|
sb.Append(hashValue[i].ToString("x2"));
|
114
|
}
|
115
|
break;
|
116
|
}
|
117
|
return sb.ToString();
|
118
|
}
|
119
|
|
120
|
#endregion
|
121
|
|
122
|
#region 第二步:定义web请求方法
|
123
|
//POST方式发送得结果
|
124
|
public string doPostRequest(out string errMsg, string url, string data)
|
125
|
{
|
126
|
errMsg = "";
|
127
|
|
128
|
string strURL = url;
|
129
|
System.Net.HttpWebRequest request;
|
130
|
request = (System.Net.HttpWebRequest)WebRequest.Create(strURL);
|
131
|
request.Method = "POST";
|
132
|
request.ContentType = "application/json;charset=UTF-8";
|
133
|
|
134
|
string paraUrlCoded = data;
|
135
|
byte[] payload;
|
136
|
payload = System.Text.Encoding.UTF8.GetBytes(paraUrlCoded);
|
137
|
request.ContentLength = payload.Length;
|
138
|
Stream writer = request.GetRequestStream();
|
139
|
writer.Write(payload, 0, payload.Length);
|
140
|
writer.Close();
|
141
|
System.Net.HttpWebResponse response;
|
142
|
response = (System.Net.HttpWebResponse)request.GetResponse();
|
143
|
System.IO.Stream s;
|
144
|
s = response.GetResponseStream();
|
145
|
string StrDate = "";
|
146
|
string strValue = "";
|
147
|
StreamReader Reader = new StreamReader(s, Encoding.UTF8);
|
148
|
while ((StrDate = Reader.ReadLine()) != null)
|
149
|
{
|
150
|
strValue += StrDate + "\r\n";
|
151
|
}
|
152
|
return strValue;
|
153
|
}
|
154
|
#endregion
|
155
|
|
156
|
#region 第三步:定义接口请求方法
|
157
|
/// <summary>
|
158
|
/// 调用接口
|
159
|
/// </summary>
|
160
|
/// <param name="err_msg">请求结果信息</param>
|
161
|
/// <param name="url">请求接口地址</param>
|
162
|
/// <param name="postParam">请求参数Model,实体类模型</param>
|
163
|
/// <returns>是否成功</returns>
|
164
|
public bool RequestToAPI<T>(out string msg, string url, T postParam)
|
165
|
{
|
166
|
msg = "";
|
167
|
string jsonStr = JsonConvert.SerializeObject(postParam);
|
168
|
string ret = doPostRequest(out msg, url, jsonStr);
|
169
|
|
170
|
var rdata = JsonConvert.DeserializeObject<JObject>(ret);
|
171
|
|
172
|
if (!Convert.ToBoolean(rdata["status"]))
|
173
|
{
|
174
|
msg = rdata["message"].ToString();
|
175
|
return false;
|
176
|
}
|
177
|
else
|
178
|
{
|
179
|
msg = rdata["message"].ToString();
|
180
|
return true;
|
181
|
}
|
182
|
}
|
183
|
#endregion
|
184
|
|
185
|
}
|
186
|
|
187
|
/// <summary>
|
188
|
/// URl参数列表
|
189
|
/// </summary>
|
190
|
public class ExpenseSettlement
|
191
|
{
|
192
|
public string InsuranceType { get; set; } // 险种
|
193
|
public string PolicyNo { get; set; } // 保单号
|
194
|
public string Channel { get; set; } // 渠道
|
195
|
public string SigningDate { get; set; } // 签单日期
|
196
|
public string StartDate { get; set; } // 保险期限开始
|
197
|
public string EndDate { get; set; } // 保险期限结束
|
198
|
public string InsuerCorp { get; set; } // 保险公司
|
199
|
public string Tax { get; set; } // 车船税
|
200
|
public string TaxExpenseRate { get; set; } // 车船税结费比例
|
201
|
public string TotalAmount { get; set; } // 保额
|
202
|
public string Premium { get; set; } // 保费
|
203
|
public string ExpenseRate { get; set; } // 保费结费比例
|
204
|
public string ExpensesActual { get; set; } // 应结费用
|
205
|
public string InsuranceDetails { get; set; } // 相关的险种明细(交强+商业)
|
206
|
public string ChargeType { get; set; } // 刷卡方式
|
207
|
public string PaymentType { get; set; } // 缴费方式
|
208
|
public string PlateNo { get; set; } // 号牌号码
|
209
|
public string BrandModel { get; set; } // 品牌型号
|
210
|
public string Owner { get; set; } // 车主
|
211
|
public string RegisterDate { get; set; } // 初登日期
|
212
|
public string EngineNo { get; set; } // 发动机号
|
213
|
public string VIN { get; set; } // 识别代码(VIN)
|
214
|
public string UseCharacter { get; set; } // 使用性质
|
215
|
public string VehicleType { get; set; } // 车辆类型
|
216
|
public string VehicleKind { get; set; } // 车辆种类
|
217
|
public string Displacement { get; set; } // 排量
|
218
|
public string Passengers { get; set; } // 座位数
|
219
|
public string IsNewCar { get; set; } // 是否新车
|
220
|
public string AllQuality { get; set; } // 整备
|
221
|
public string LoadQuality { get; set; } // 核载
|
222
|
public string IssueInsType { get; set; } // 单双保
|
223
|
public string IsContainCS { get; set; } // 投保车损
|
224
|
public string OriginalSigningDate { get; set; } // 原保单签单日期
|
225
|
public string PurchaseValence { get; set; } // 购置价
|
226
|
public string IsImport { get; set; } // 是否进口车
|
227
|
public string IsContainDaoQiang { get; set; } // 投保盗抢
|
228
|
public string ClaimTimes { get; set; } // 出险次数
|
229
|
public string ClaimTotalAmount { get; set; } // 出现赔款合计
|
230
|
public string PayTaxType { get; set; } // 纳税类型
|
231
|
public string NCDType { get; set; } // NCD系数
|
232
|
public string BusinessQuality { get; set; } // 业务品质
|
233
|
public string WholeDiscount { get; set; } // 渠道核保因子
|
234
|
public string ThirdPartyLiabilityAmount { get; set; } // 第三者责任险保额
|
235
|
public string LastYearStartDate { get; set; } // 上年保险起期
|
236
|
public string ConfirmTime { get; set; } // 确认缴费日期
|
237
|
public string EcompensationRate { get; set; } // 预期赔付率
|
238
|
public string TotalEcompensationRate { get; set; } // 交商合计预期赔付率
|
239
|
public string TransferBeforePlate { get; set; } // 过户前车牌号
|
240
|
public string InsuredName { get; set; } // 被保险人姓名
|
241
|
public string InsuredCertType { get; set; } // 被保险人证件类型
|
242
|
public string InsuredCertNo { get; set; } // 被保险人证件号码
|
243
|
public string PolicyHolderName { get; set; } // 投保人姓名
|
244
|
public string PolicyHolderCertType { get; set; } // 投保人证件类型
|
245
|
public string PolicyHolderCertNo { get; set; } // 投保人证件号码
|
246
|
public string BeneficiaryName { get; set; } // 受益人姓名
|
247
|
public string BeneficiaryCertType { get; set; } // 受益人证件类型
|
248
|
public string BeneficiaryCertNo { get; set; } // 受益人证件号码
|
249
|
public string Description3 { get; set; } // 生存受益人姓名
|
250
|
public string Description4 { get; set; } // 身故受益人姓名
|
251
|
public string EntryTimeDateL { get; set; } // 录入日期
|
252
|
public string CusType { get; set; } // 客户类别
|
253
|
public string BusinessManID { get; set; } // 业务员
|
254
|
public string Agreement { get; set; } // 特别约定
|
255
|
public string DownloadSourceType { get; set; } // 数据来源(ERP同步)D0015
|
256
|
public string Comment { get; set; } // 备注
|
257
|
|
258
|
public string signature { get; set; }// 签名
|
259
|
public string signMethod { get; set; }// 签名方法
|
260
|
public string customerID { get; set; }// 操作用户ID
|
261
|
public string token { get; set; }// 操作用户token
|
262
|
public string orgID { get; set; }// 机构ID
|
263
|
|
264
|
}
|
265
|
|
266
|
public partial class _Default : Page
|
267
|
{
|
268
|
//调用接口示例
|
269
|
protected void Page_Load(object sender, EventArgs e)
|
270
|
{
|
271
|
try
|
272
|
{
|
273
|
string msg = "";
|
274
|
Test ts = new Test();
|
275
|
var ret = true;
|
276
|
|
277
|
ExpenseSettlement p = new ExpenseSettlement
|
278
|
{
|
279
|
InsuranceType = "延保",
|
280
|
PolicyNo = "P998q821231312100002",
|
281
|
Channel = "上海宝景汽车销售服务有限公司",
|
282
|
SigningDate = "2019-04-01",
|
283
|
StartDate = "2019-04-10",
|
284
|
EndDate = "2020-04-09",
|
285
|
InsuerCorp = "中国人民财产保险股份有限公司青岛分公司市南支公司",
|
286
|
Tax = "360",
|
287
|
TaxExpenseRate = "2",
|
288
|
TotalAmount = "200000",
|
289
|
Premium = "2000",
|
290
|
ExpenseRate = "30",
|
291
|
ExpensesActual = "520",
|
292
|
InsuranceDetails = "",
|
293
|
ChargeType = "CT999992",
|
294
|
PaymentType = "PT999995",
|
295
|
PlateNo = "鲁B123456",
|
296
|
BrandModel = "五菱宏光121323",
|
297
|
Owner = "张三",
|
298
|
RegisterDate = "2019-01-13",
|
299
|
EngineNo = "123456",
|
300
|
VIN = "111111111111",
|
301
|
UseCharacter = "01",
|
302
|
VehicleType = "02",
|
303
|
VehicleKind = "02",
|
304
|
Displacement = "1.5",
|
305
|
Passengers = "5",
|
306
|
IsNewCar = "否",
|
307
|
AllQuality = "111.3",
|
308
|
LoadQuality = "222.66",
|
309
|
IssueInsType = "01",
|
310
|
IsContainCS = "否",
|
311
|
OriginalSigningDate = "2019-02-01",
|
312
|
PurchaseValence = "1212.21",
|
313
|
IsImport = "否",
|
314
|
IsContainDaoQiang = "否",
|
315
|
ClaimTimes = "3",
|
316
|
ClaimTotalAmount = "22222.2",
|
317
|
PayTaxType = "01",
|
318
|
NCDType = "0.60",
|
319
|
BusinessQuality = "0",
|
320
|
WholeDiscount = "11",
|
321
|
ThirdPartyLiabilityAmount = "22",
|
322
|
LastYearStartDate = "2018-09-01",
|
323
|
ConfirmTime = "2018-05-01",
|
324
|
EcompensationRate = "43",
|
325
|
TotalEcompensationRate = "12",
|
326
|
TransferBeforePlate = "鲁B988765",
|
327
|
InsuredName = "张三",
|
328
|
InsuredCertType = "01",
|
329
|
InsuredCertNo = "370703198308140518",
|
330
|
PolicyHolderName = "张三",
|
331
|
PolicyHolderCertType = "01",
|
332
|
PolicyHolderCertNo = "370703198308140518",
|
333
|
BeneficiaryName = "李四",
|
334
|
BeneficiaryCertType = "01",
|
335
|
BeneficiaryCertNo = "370703198308140519",
|
336
|
Description3 = "生存受益人1",
|
337
|
Description4 = "身故受益人1",
|
338
|
EntryTimeDateL = "2019/04/15 12:00:00",
|
339
|
CusType = "01",
|
340
|
Agreement = "特别约定XXXXXXX",
|
341
|
Comment = "备注XXX", //备注
|
342
|
BusinessManID = "赵福来|13645322601",
|
343
|
|
344
|
|
345
|
customerID = "U0000000000000000000000000000000", //固定值
|
346
|
token = "T0000000000000000000000000000000", //固定值
|
347
|
orgID = "G5000001" //固定值
|
348
|
};
|
349
|
|
350
|
p.signature = ts.getSignCNT(JsonConvert.DeserializeObject<JObject>(JsonConvert.SerializeObject(p)));
|
351
|
p.signMethod = "MD5"; //固定值
|
352
|
|
353
|
ret = ts.RequestToAPI(out msg, "http://proxy1.countnet.cn:20801/VehicleInsurance3/Index?method=SaveNewInsYBT", p);
|
354
|
//ret = ts.RequestToAPI(out msg, "http://localhost:31681/VehicleInsurance3/Index?method=SaveNewInsYBT", p);
|
355
|
|
356
|
|
357
|
lbluuuuu.Text = msg;
|
358
|
|
359
|
}
|
360
|
catch (Exception ex)
|
361
|
{
|
362
|
|
363
|
}
|
364
|
}
|
365
|
}
|
366
|
|
367
|
|