admin管理员组文章数量:1566679
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
{
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 tring>(); ("content", ""); //内容 ("size", ""); //图片大小(范围:1~10),默认为4【注: 手机扫描,size为4即可】 ("level", ""); //容错(0:L,1:M,:2:H,3:Q),默认为0 ("margin", ""); //边框大小(范围:1~10),默认为3 Dictionary 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 { 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 tring>(); ("image", ""); //二维码图片文件 Dictionary 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(); } } }
版权声明:本文标题:eoLinker-API_Shop_二维码编解码_API接口_C#调用示例代码 内容由热心网友自发贡献,该文观点仅代表作者本人,
转载请联系作者并注明出处:https://www.elefans.com/xitong/1721861644a901698.html,
本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论