商品条码生成
ROLL 官方文档
根据内容生成指定的条形码
基本说明:
接口地址:https://www.mxnzp.com/api/barcode/create
返回格式:json
请求方式:get
请求示例:https://www.mxnzp.com/api/barcode/create?content=6902538005141&width=500&height=300&type=0&app_id=&app_secret=
请求参数说明:
名称 类型 必填 说明
app_id string 必填 app_id 扫码关注公众号
app_secret string 必填 app_secret 扫码关注公众号
content string 必填 需要生成二维码的商品code值
width int 必填 生成的图片宽度,默认500
height int 必填 生成图片的高度,默认300
type int 选填 返回类型,0-生成条形码图片的地址链接 1-生成条形码图片的base64字符串
返回参数说明:
名称 类型 说明
content string 图片对应的商品code值
barCodeUrl string 如果type=0 则此参数会有值,且此值会返回条形码的下载链接
barCodeBase64 string 如果type=1 则此参数会有值,且此值会返回条形码的base64字符串
type int 对应类型
JSON返回示例:
{
	"code": 1,
	"msg": "数据返回成功!",
	"data": {
		"barCodeUrl": "http://www.mxnzp.com/api_file/barcode/b/d/3/b/4/a/c/1/6d5a7a258176487588ad781d2c4014ca.png",
		"content": "6902538005141",
		"type": 0,
		"barCodeBase64": null
	}
}
服务级错误码参照
错误码 说明
0 app_id或者app_secret不合法
完整教学代码示例
<?php
/**
 * Created by PhpStorm.
 * User: FZS
 * Time: 2022/08/04 14:56
 */
class freeApi
{
    private $apiUrl;

    public function __construct()
    {
        $this->apiUrl = 'https://www.mxnzp.com/api/barcode/create?content=6902538005141&width=500&height=300&type=0&app_id=&app_secret=';
    }

    /**
     * 获取结果
     * @return array
     */
    public function getResult()
    {
        return file_get_contents($this->apiUrl);
    }
}
package main

import (
	"fmt"
	"io/ioutil"
	"log"
	"net/http"
)

const (
	APIURL   = "https://www.mxnzp.com/api/barcode/create?content=6902538005141&width=500&height=300&type=0&app_id=&app_secret="
)

func main() {
	queryUrl := fmt.Sprintf("%s",APIURL)
	resp, err := http.Get(queryUrl)
	if err != nil {
		log.Println(err)
		return
	}

	defer resp.Body.Close()

	body, err := ioutil.ReadAll(resp.Body)

	if err != nil {
		fmt.Println(err)
		return
	}

	fmt.Println(string(body))
}