Commit cc1684b1 by mahaisong

fix:国海接口

parent 8f5da305
using Newtonsoft.Json;
using Newtonsoft.Json;
......@@ -155,9 +155,9 @@ namespace TestC
}
}
// Methods
//private static bool CheckValidationResult(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors errors) =>
// true;
//Methods
private static bool CheckValidationResult(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors errors) =>
true;
private void authAndGetToken()
......@@ -170,7 +170,7 @@ namespace TestC
//将data按照Base64编码,以HTTP的形式post(内部代码只是UTF-8了一下,头部没加内容,返回值得到content)
string jsonbody = CryptoUtil.RSAEncryptByPublicKey(JsonConvert.SerializeObject(credential));
//ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(CheckValidationResult);
ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(CheckValidationResult);
HttpWebRequest request = WebRequest.Create(this.enpoint + "/auth") as HttpWebRequest;
request.ProtocolVersion = HttpVersion.Version10;
request.Method = "POST";
......@@ -205,38 +205,35 @@ namespace TestC
}
//外部调用发送post请求,自动封装token,(注意参数cmd、param、路径api、secretToken,这写法都是约定好的)
public String sendRequest(String cmd, IDictionary<string, string> parameters)
public String sendRequest(String cmd, JObject parameters)
{
KV tokenHeader = new KV("gh-sec-token", this.secretToken);
JObject payload = new JObject();
payload["cmd"] = cmd;
payload["param"] = parameters;
string bodyStr = JsonConvert.SerializeObject(payload);
HttpWebRequest request = WebRequest.Create(this.enpoint + "/api") as HttpWebRequest;
request.Headers.Add("gh-sec-token", this.secretToken);
request.Headers.Add(tokenHeader.key, tokenHeader.value);
request.ProtocolVersion = HttpVersion.Version10;
request.Method = "POST";
request.ContentType = "application/x-www-form-urlencoded";
//request.ContentType = "application/json";
//request.ContentType = "application/x-www-form-urlencoded";
request.ContentType = "application/json";
if ((parameters != null) && (parameters.Count > 0))
{
StringBuilder builder = new StringBuilder();
int num = 0;
foreach (string str in parameters.Keys)
{
if (num > 0)
{
builder.AppendFormat("&{0}={1}", str, parameters[str]);
}
else
if (!String.IsNullOrWhiteSpace(bodyStr))
{
builder.AppendFormat("{0}={1}", str, parameters[str]);
}
num++;
}
byte[] bytes = System.Text.Encoding.UTF8.GetBytes(builder.ToString());
byte[] bytes = System.Text.Encoding.UTF8.GetBytes(bodyStr.ToString());
using (Stream stream = request.GetRequestStream())
{
stream.Write(bytes, 0, bytes.Length);
}
}
System.Net.HttpWebResponse publicresponse = (request.GetResponse() as HttpWebResponse);
StreamReader publicsr = new StreamReader(publicresponse.GetResponseStream(), Encoding.UTF8);
String resp = publicsr.ReadToEnd();
......
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace TestC
{
public class KV
{
public String key;
public String value;
public KV()
{
}
public KV(String k, String v)
{
this.key = k;
this.value = v;
}
//得到
public static String urlFormed(KV[] param)
{
StringBuilder payload = new StringBuilder();
KV[] arrayOfKV = param;
//得到KV对象数组的拼接结果,
foreach (var item in arrayOfKV)
{
KV pa = item;
payload.Append(System.Web.HttpUtility.UrlEncode(pa.key, Encoding.UTF8))
.Append(System.Web.HttpUtility.UrlEncode(pa.value, Encoding.UTF8))
.Append("&");
}
payload= payload.Remove(payload.Length - 1,1);
return payload.ToString();
}
}
}
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
......@@ -40,6 +40,7 @@
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Web" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
......@@ -50,6 +51,7 @@
<ItemGroup>
<Compile Include="CryptoUtil.cs" />
<Compile Include="ESBFinder.cs" />
<Compile Include="KV.cs" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="RSAKeyConvert.cs" />
......
1290beb12b29130f16d5081ca87b95ec21f0ed54
2dc95b9ac18ba069502ac00f0465914a0420bd47
1290beb12b29130f16d5081ca87b95ec21f0ed54
2dc95b9ac18ba069502ac00f0465914a0420bd47
using System;
using System;
using System;
using System.Collections.Generic;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Newtonsoft.Json.Linq;
using TestC;
namespace UnitTestProject1
......@@ -13,7 +14,7 @@ namespace UnitTestProject1
{
String appid = "Mys77mkOyevOXMx0"; // APPID
String secret = "f00f8f8ea15e5d314d4ccb419c2e176d"; // APP密钥串
String serviceEndpoint = "http://113.16.174.140:8024/ESBFinder"; // 服务器地址,请根据实际情况修改
String serviceEndpoint = "http://113.16.174.140:8024/finder"; // 服务器地址,请根据实际情况修改
String sdkCertificate = "ESBFinder_SDK.crt"; // 公钥证书文件
/**
......@@ -33,9 +34,9 @@ namespace UnitTestProject1
* 2: 设定接口参数
*/
String cmd = "moni.getStockAction";
IDictionary<string, string> parameters = new Dictionary<string, string>();
parameters.Add("username", "00000");
parameters.Add("password", "11111");
JObject parameters = new JObject();
parameters["username"] = "00000";
parameters["password"] = "11111";
/**
* 3:发起请求,获取返回
......
package test;
package test;
......@@ -19,7 +19,7 @@ public class SDKTest {
public static void main(String[] args) throws ESBFinderException {
String appid ="Mys77mkOyevOXMx0"; // APPID
String secret="f00f8f8ea15e5d314d4ccb419c2e176d"; // APP密钥串
String serviceEndpoint="http://localhost:8085/ESBFinder"; // 服务器地址,请根据实际情况修改
String serviceEndpoint="http://113.16.174.140:8024/finder"; // 服务器地址,请根据实际情况修改
String sdkCertificate="D:\\smallproject\\14.java转C#\\ESBFinder_SDK.crt"; // 公钥证书文件
/**
......
No preview for this file type
## 接口文档##
## 接口文档##
[TOC]
### 接口说明 **1、**新增机器人 ###
- **请求URL**
> HTTP/1.1[api/v2/operating/newRobot](#)
- **请求方式**
>**GET/POST**
- **请求参数**
>Content-Type: application/json
>
| 请求参数 | 参数类型/是否为空 | 参数说明 |
| :-------- | :--------| :------ |
| uid| <mark>Long,**不可为空**</mark>| 机器人UID|
| status| Integer,可为空| 机器人可用性,默认可用 **-1.不可使用 1.可用**|
| AccessToken| bbd70056c684475e8471a78b530c4501 _3634f1f4d49041c7b49b305e516dac66| token|
- **返回参数**
> | 返回参数 | 参数类型 | 参数说明 |
| :-------- | :--------| :------ |
| success| boolean| 请求成功与否|
| code| Integer| 执行结果code|
| message| String| 执行结果消息|
- **返回示例1**
`
{
"success": true,
"code": 200,
"message": "操作正确"
}`
- **返回示例2**
`
{
"success": false,
"code": 404,
"message": "操作错误"
}`
<pre>
cate_id 分类ID Array(不传显示全部) [1,3,6]
page_num 当前页码(可不传) 默认 1
page_size 每页记录数目(可不填) 默认 10
</pre>
Markdown | Less | Pretty
--- | --- | ---
*Still* | `renders` | **nicely**
1 | 2 | 3
### 返回值 ###
<pre>
total: 108,
list: [
{
id: 2718,
cate_id: 2,
cate_name: "php",
view_cnt: "1005",
cate_name: "php",
name: "Yii2中配置使用连接多个数据库连接",
url: "http://www.dodobook.net/php/2718",
post_date: "2016-08-20 20:10:08",
img_logo: "/upload/img/aaa.png",
},
{
id: 2718,
cate_id: 2,
cate_name: "php",
view_cnt: "1005",
cate_name: "php",
name: "PHP实现网址短链接转换的方法",
url: "http://www.dodobook.net/php/2710",
post_date: "2016-08-16 20:10:08",
img_logo: "/upload/img/addsaafff.png",
}
]
</pre>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment