import com.chinaums.open.api.OpenApiCache;
import com.chinaums.open.api.OpenApiContext;
import com.chinaums.open.api.constants.ConfigBean;
import com.chinaums.open.api.internal.util.http.HttpTransport;
import java.util.UUID;
public class OpenApiSdkTest {
public static void main(String[] args) throws Exception{
String url = "/v1/invoice/get-qrcode";
//开发者ID
String appId = "平台分配";
//开发者秘钥
String appKey = "平台分配";
//实例化客户端
ConfigBean configBean = new ConfigBean();
OpenApiContext context = new OpenApiContext();
String request = "{\"invoiceMaterial\":\"\",
\"invoiceType\":\"\",
\"merchantId\":\"\",
\"terminalId\":\"\",
\"merOrderDate\":\"\",
\"merOrderId\":\"\",
\"amount\":\"\",
\"deductionAmount\":\"\",
\"goodsDetail\":\"\",
\"notifyUrl\":\"\",
\"remark\":\"\",
\"expireTime\":\"\"}";
context.setStartTime(System.currentTimeMillis());
context.setRequestId(UUID.randomUUID().toString().replace("-", ""));
context.setOpenServUrl(url.split("/v")[0].concat("/"));
context.setApiServiceUrl(url);
context.setVersion(url.split("/")[3]);
context.setAppId(appId);
context.setAppKey(appKey);
context.setConfigBean(configBean);
context.setServiceCode(url.split("/v")[1].substring(1));
OpenApiCache.getCurrentToken(context);
System.out.println(HttpTransport.getInstance().doPost(context, request));
}
}
<?php
require_once "../utils/Log.php";
require_once "../utils/Tools.php";
require_once "../DefaultOpenApiClient.php";
class DataRequest
{
public $url = "";
public $serviceCode = "";
public $apiVersion ="";
public $needToken = true;
public $needDataTag = false;
public $data;
function __construct($data, $url)
{
$this->data = $data;
$apiVersion = preg_split("/[/]+/s",$url)[2];
$this->apiVersion = $apiVersion;
$serviceCode = strstr($url,$apiVersion);
$this->url = strstr($url,"/".$apiVersion,true);
$this->serviceCode = preg_replace("/^" . preg_quote($apiVersion, "/") . "/", "", $serviceCode);
}
}
class DataDemo{
public function main(){
$appid = "平台分配";
$appkey = "平台分配";
$url = "/v1/invoice/get-qrcode";
$data = json_encode(array("invoiceMaterial"=>"",
"invoiceType"=>"",
"merchantId"=>"",
"terminalId"=>"",
"merOrderDate"=>"",
"merOrderId"=>"",
"amount"=>"",
"deductionAmount"=>"",
"goodsDetail"=>"",
"notifyUrl"=>"",
"remark"=>"",
"expireTime"=>""));
$reqiest = new DataRequest($data,$url);
$client = new DefaultOpenApiClient();
$content = $client->execute($reqiest,$appid,$appkey);
$obj = json_decode($content);
print_r($obj->errCode);
print_r($obj->errInfo);
}
}
$p = new DataDemo();
$p->main();
?>
# -*- coding: utf-8 -*-
from webapi.DefaultOpenApiClient import DefaultOpenApiClient
url = "/v1/invoice/get-qrcode"
class DataRequest(object):
def __init__(self, data: dict) -> dict:
self.data = data
self.serviceCode = url[len(url.split("/v")[0])+len(url.split("/")[3])+1: len(url)]
self.apiVersion = url.split("/")[3]
self.needToken = True
self.needDataTag = True
appId="平台分配"
appKey="平台分配"
client = DefaultOpenApiClient(appId, appKey)
cls = DataRequest({\"invoiceMaterial\":\"\",
\"invoiceType\":\"\",
\"merchantId\":\"\",
\"terminalId\":\"\",
\"merOrderDate\":\"\",
\"merOrderId\":\"\",
\"amount\":\"\",
\"deductionAmount\":\"\",
\"goodsDetail\":\"\",
\"notifyUrl\":\"\",
\"remark\":\"\",
\"expireTime\":\"\"})
response = client.execute(cls)
print(str(response.get("data")))
print(response.get("errCode"))
print(response.get("errInfo"))
print(response.get("resultCode"))
print(response.get("resultInfo"))
生成开票二维码
URL
- 生产环境:
POST
https://api-mop.chinaums.com/v1/invoice/get-qrcode
描述:进行生成开票二维码操作
ContentType:application/json
请求头
名称 | 必填 | 描述 | 示例值 |
---|---|---|---|
Authorization | 是 | 认证内容 | OPEN-BODY-SIG AppId="****",Timestamp="20170606135700",Nonce="99930a147f5353dd8a8f29a5329f37e9",Signature="IPmdGHYCcfN+mto0/02zkwoUF1NT3YqPKaUykMaec1T=" |
请求参数
名称 | 类型 | 必填 | 最大长度 | 描述 | 示例值 |
---|---|---|---|---|---|
invoiceMaterial | string | 是 | 64 | 发票材质; 纸质发票:PAPER 电子发票:ELECTRONIC | |
invoiceType | string | 是 | 64 | 发票类型; 普通发票: PLAIN 增值税专用发票: VAT 支持三种类型的发票:电子普通发 票/纸质普通发票/纸质增值税专 用发票 | |
merchantId | string | 是 | 64 | 银商商户号 | |
terminalId | string | 是 | 64 | 银商终端号 | |
merOrderDate | string | 是 | 64 | 格式 yyyyMMdd,建议使用原交易 支付日期 | |
merOrderId | string | 是 | 64 | 建议使用原交易订单号(每笔交易 必须保证唯一,需按照规则生成, 以避免跟其他系统冲突,也避免重 复开票) | |
amount | number | 是 | 64 | 单位为分 | |
deductionAmount | number | 否 | 64 | 单位为分 为空:普通征税 不为空:差额征税 扣除额必须小于开票金额 | |
goodsDetail | string | 否 | 为空:使用平台配置的单个默认商品 不为空: 单个商品或多个商品 | ||
index | number | 是 | 64 | 行号,从 1 开始 | |
attribute | string | 是 | 64 | 0: 正常行 1: 折扣行 2: 被折扣行 | |
discountIndex | number | 否 | 64 | 折行对应行号(有折扣,必填) | |
name | string | 是 | 64 | 折扣行与被折扣行一致 | |
sn | string | 是 | 64 | 商品编码 参考《商品和服务税收分类与编码》 .xls | |
taxRate | number | 是 | 64 | 税率 | |
priceIncludingTax | number | 是 | 64 | 单位为元 折扣行为负数 | |
quantity | number | 否 | 64 | 默认为 1.0 | |
unit | string | 否 | 64 | 单位 | |
model | string | 否 | 64 | 规格型号 | |
freeTaxType | string | 否 | 64 | 空:正常税率 1:出口免税和其他免税优惠政策 2:不征增值税 3:普通零税率 | |
preferPolicyFlag | string | 否 | 64 | 0:否 1:是 | |
vatSpecial | string | 否 | 64 | 增值税特殊管 理 | |
notifyUrl | string | 否 | 64 | 商户接收开票结果通知的地址,按开票结果通知接口开发 注:为空则使用后台配置地址 | |
remark | string | 否 | 64 | 可填写房间号或桌号,体现在票面备注栏 | |
expireTime | string | 否 | 64 | 过期时间 单位为分钟。表示生成二维码后 N分钟内不扫码,二维码自动过期。 不设置,则表示不过期 |
响应示例
{
"resultCode":"",
"resultMsg":"",
"responseTimestamp":"",
"qrCode":"",
"status":""
}
响应参数
名称 | 类型 | 必填 | 最大长度 | 描述 | 示例值 |
---|---|---|---|---|---|
resultCode | string | 是 | 64 | SUCCESS 表示成功 | |
resultMsg | string | 是 | 64 | 错误信息 | |
responseTimestamp | string | 是 | 64 | 应答时间 yyyy-MM-dd HH:mm:ss | |
qrCode | string | 是 | 64 | 二维码 | |
status | string | 是 | 64 | PENDING:待开具 ISSUING:开具中 ISSUED:已开具 REVERSING:红冲中 REVERSED:已红冲 CLOSED:已关闭 |