<?php
require_once 'curl.func.php';
$appkey = 'your_appkey_here';
$type = 'ean13';
$barcode = '6901236341056';
$fontsize = 12;
$dpi = 72;
$scale = 2;
$height = 40;
$url = "https://api.jisuapi.com/barcode/generate?appkey=$appkey&type=$type&barcode=$barcode&fontsize=$fontsize&dpi=$dpi&scale=$scale&height=$height";
$result = curlOpen($url, ['ssl'=>true]);
$jsonarr = json_decode($result, true);
//exit(var_dump($jsonarr));
if($jsonarr['status'] != 0)
{
echo $jsonarr['msg'];
exit();
}
$result = $jsonarr['result'];
$content = $result['barcode'];
echo $result['code'].' '.$result['fontsize'].' '.$result['dpi'].' '.$result['scale'].' '.$result['height'].'
';
//file_put_contents('barcode.png', base64_decode($content));
echo "
";
package api.jisuapi.barcode;
import api.util.HttpUtil;
import net.sf.json.JSONObject;
public class Generate {
public static final String APPKEY = "your_appkey_here";// 你的appkey
public static final String URL = "https://api.jisuapi.com/barcode/generate";
public static final String type = "ean13";
public static final String barcode = "6901236341056";
public static final String fontsize = "12";
public static final String dpi = "72";
public static final String scale = "2";
public static final String height = "40";
public static void Get() {
String result = null;
String url = URL + "?appkey=" + APPKEY + "&type=" + type + "&barcode=" + barcode + "&fontsize=" + fontsize
+ "&dpi=" + dpi + "&scale=" + scale + "&height=" + height;
try {
result = HttpUtil.sendGet(url, "utf-8");
JSONObject json = JSONObject.fromObject(result);
if (json.getInt("status") != 0) {
System.out.println(json.getString("msg"));
} else {
JSONObject resultarr = json.optJSONObject("result");
String type = resultarr.getString("type");
String fontsize = resultarr.getString("fontsize");
String dpi = resultarr.getString("dpi");
String scale = resultarr.getString("scale");
String height = resultarr.getString("height");
String barcode = resultarr.getString("barcode");
System.out.println(type + " " + fontsize + " " + dpi + " " + scale + " " + height + " " + barcode);
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
import requests
appkey = 'your_appkey_here'
type = 'ean13'
barcode = '6901236341056'
fontsize = 12
dpi = 72
scale = 2
height = 40
url = f"https://api.jisuapi.com/barcode/generate?appkey={appkey}&type={type}&barcode={barcode}&fontsize={fontsize}&dpi={dpi}&scale={scale}&height={height}"
result = requests.get(url).text
jsonarr = requests.get(url).json()
if jsonarr['status'] != 0:
print(jsonarr['msg'])
else:
result = jsonarr['result']
content = result['barcode']
print(result['code'], result['fontsize'], result['dpi'], result['scale'], result['height'])
print(f'
')
using System;
using System.IO;
using System.Net.Http;
using System.Threading.Tasks;
using Newtonsoft.Json.Linq;
class Barcode
{
// 替换成你的AppKey
private const string AppKey = "YOUR_APPKEY_HERE";
public static async Task GenerateAsync(string Barcode, string Type="ean13", int Fontsize=12, int Dpi=72, int Scale=2, int Height=40)
{
try
{
// 构建请求 URL
string url = $"https://api.jisuapi.com/barcode/generate?appkey={AppKey}&type={Type}&barcode={Barcode}&fontsize={FontSize}&dpi={Dpi}&scale={Scale}&height={Height}";
using (HttpClient client = new HttpClient())
{
// 发送 GET 请求
HttpResponseMessage response = await client.GetAsync(url);
// 确保请求成功
response.EnsureSuccessStatusCode();
// 读取响应内容
string responseBody = await response.Content.ReadAsStringAsync();
// 解析 JSON 数据
JObject jsonarr = JObject.Parse(responseBody);
// 检查状态码
if (jsonarr["status"] != null && (int)jsonarr["status"] != 0)
{
if (jsonarr["msg"] != null)
{
Console.WriteLine(jsonarr["msg"]);
}
return;
}
// 获取结果对象
JObject result = (JObject)jsonarr["result"];
if (result != null)
{
// 输出信息
Console.WriteLine($"{result["code"]} {result["fontsize"]} {result["dpi"]} {result["scale"]} {result["height"]}");
// 获取 Base64 编码的条形码内容
string content = (string)result["barcode"];
// 若要保存图片,可取消以下注释
// SaveBarcodeToFile(content, "barcode.png");
// 模拟输出 HTML 图片标签(控制台输出)
Console.WriteLine($"
");
}
}
}
catch (HttpRequestException ex)
{
Console.WriteLine($"请求出错: {ex.Message}");
}
catch (Exception ex)
{
Console.WriteLine($"发生错误: {ex.Message}");
}
}
private static void SaveBarcodeToFile(string base64Content, string filePath)
{
byte[] imageBytes = Convert.FromBase64String(base64Content);
File.WriteAllBytes(filePath, imageBytes);
Console.WriteLine($"条形码已保存到 {filePath}");
}
public static async Task Main()
{
// 生成条形码
await Barcode.GenerateAsync("6901236341056");
// 读取条形码
await Barcode.ReadAsync("https://api.jisuapi.com/barcode/barcode/1471602033673149.png");
}
}