admin管理员组

文章数量:1530842

2024年7月25日发(作者:)

eoLinker-API Shop 二维码编解码 C#调用示例代码

二维码编解码

支持二维码的生成与识别。二维码生成时,直接返回生成的二维码图片

该产品拥有以下APIs:

1. 二维码生成

2. 二维码解码

注意,该示例代码仅适用于 网站下API 使用该产品前,您需要

通过 /#/api/detail/?productID=128 申请API服务

1.二维码生成

using System;

using c;

using ;

using ;

using ;

using ization;

namespace apishop_sdk

{

class Program

{

/**

* 转发请求到目的主机

* @param method string 请求方法

* @param url string 请求地址

* @param params Dictionary 请求参数

* @param headers Dictionary 请求头

* @return string

**/

static string apishop_send_request(string method, string url, D

ictionary param, Dictionary headers)

{

string result = ;

try

{

string paramData = "";

if (param != null && > 0)

{

StringBuilder sbuilder = new StringBuilder();

foreach (var item in param)

{

if ( > 0)

{

("&");

}

( + "=" + );

}

paramData = ng();

}

method = r();

if (method == "GET")

{

url = ("{0}?{1}", url, paramData);

}

HttpWebRequest wbRequest = (HttpWebRequest)WebRequest.C

reate(url);

if (method == "GET")

{

= "GET";

}

else if (method == "POST")

{

= "POST";

tType = "application/x-www-form-url

encoded";

tLength = eCoun

t(paramData);

using (Stream requestStream = uestS

tream())

{

using (StreamWriter swrite = new StreamWriter(r

equestStream))

{

(paramData);

}

}

}

HttpWebResponse wbResponse = (HttpWebResponse)wbRequest.

GetResponse();

using (Stream responseStream = ponseSt

ream())

{

using (StreamReader sread = new StreamReader(respon

seStream))

{

result = End();

}

}

}

catch

{

return "";

}

return result;

}

class Response

{

public string statusCode;

}

static void Main(string[] args)

{

string method = "POST";

string url = "/common/qrcode/content

2QrCode";

Dictionary param = new Dictionary

tring>();

("content", ""); //内容

("size", ""); //图片大小(范围:1~10),默认为4【注:

手机扫描,size为4即可】

("level", ""); //容错(0:L,1:M,:2:H,3:Q),默认为0

("margin", ""); //边框大小(范围:1~10),默认为3

Dictionary headers = null;

string result = apishop_send_request(method, url, param, he

aders);

if (result == "")

{

//返回内容异常,发送请求失败

ine("发送请求失败");

return;

}

Response res = new JavaScriptSerializer().Deserialize

nse>(result);

if (Code == "000000")

{

//状态码为000000, 说明请求成功

ine(("请求成功: {0}", resul

t));

}

else

{

//状态码非000000, 说明请求失败

ine(("请求失败: {0}", resul

t));

}

ne();

}

}

}

2.二维码解码

using System;

using c;

using ;

using ;

using ;

using ization;

namespace apishop_sdk

{

class Program

{

/**

* 转发请求到目的主机

* @param method string 请求方法

* @param url string 请求地址

* @param params Dictionary 请求参数

* @param headers Dictionary 请求头

* @return string

**/

static string apishop_send_request(string method, string url, D

ictionary param, Dictionary headers)

{

string result = ;

try

{

string paramData = "";

if (param != null && > 0)

{

StringBuilder sbuilder = new StringBuilder();

foreach (var item in param)

{

if ( > 0)

{

("&");

}

( + "=" + );

}

paramData = ng();

}

method = r();

if (method == "GET")

{

url = ("{0}?{1}", url, paramData);

}

HttpWebRequest wbRequest = (HttpWebRequest)WebRequest.C

reate(url);

if (method == "GET")

{

= "GET";

}

else if (method == "POST")

{

= "POST";

tType = "application/x-www-form-url

encoded";

tLength = eCoun

t(paramData);

using (Stream requestStream = uestS

tream())

{

using (StreamWriter swrite = new StreamWriter(r

equestStream))

{

(paramData);

}

}

}

HttpWebResponse wbResponse = (HttpWebResponse)wbRequest.

GetResponse();

using (Stream responseStream = ponseSt

ream())

{

using (StreamReader sread = new StreamReader(respon

seStream))

{

result = End();

}

}

}

catch

{

return "";

}

return result;

}

class Response

{

public string statusCode;

}

static void Main(string[] args)

{

string method = "POST";

string url = "/common/qrcode/qrCode2

Content";

Dictionary param = new Dictionary

tring>();

("image", ""); //二维码图片文件

Dictionary headers = null;

string result = apishop_send_request(method, url, param, he

aders);

if (result == "")

{

//返回内容异常,发送请求失败

ine("发送请求失败");

return;

}

Response res = new JavaScriptSerializer().Deserialize

nse>(result);

if (Code == "000000")

{

//状态码为000000, 说明请求成功

ine(("请求成功: {0}", resul

t));

}

else

{

//状态码非000000, 说明请求失败

ine(("请求失败: {0}", resul

t));

}

ne();

}

}

}

本文标签: 请求二维码示例