银联商务天满服务平台
Java PHP Python



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/invoice";
        //开发者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\":\"\",
                    \"buyerName\":\"\",
                    \"buyerTaxCode\":\"\",
                    \"buyerAddress\":\"\",
                    \"buyerTelephone\":\"\",
                    \"buyerBank\":\"\",
                    \"buyerAccount\":\"\",
                    \"notifyMobileNo\":\"\",
                    \"notifyEMail\":\"\"}";
        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/invoice";
        $data = json_encode(array("invoiceMaterial"=>"",
                    "invoiceType"=>"",
                    "merchantId"=>"",
                    "terminalId"=>"",
                    "merOrderDate"=>"",
                    "merOrderId"=>"",
                    "amount"=>"",
                    "deductionAmount"=>"",
                    "goodsDetail"=>"",
                    "notifyUrl"=>"",
                    "remark"=>"",
                    "buyerName"=>"",
                    "buyerTaxCode"=>"",
                    "buyerAddress"=>"",
                    "buyerTelephone"=>"",
                    "buyerBank"=>"",
                    "buyerAccount"=>"",
                    "notifyMobileNo"=>"",
                    "notifyEMail"=>""));
        $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/invoice"

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\":\"\",
                    \"buyerName\":\"\",
                    \"buyerTaxCode\":\"\",
                    \"buyerAddress\":\"\",
                    \"buyerTelephone\":\"\",
                    \"buyerBank\":\"\",
                    \"buyerAccount\":\"\",
                    \"notifyMobileNo\":\"\",
                    \"notifyEMail\":\"\"})
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/invoice

描述:开具发票

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 可填写房间号或桌号,体现在票面备注栏
buyerName string 64 买方名称
buyerTaxCode string 64 买方纳税人识别号
buyerAddress string 64 买方地址
buyerTelephone string 64 买方电话
buyerBank string 64 买方开户行
buyerAccount string 64 买方银行账号
notifyMobileNo string 64 推送短信手机号
notifyEMail string 64 推送手机号和邮箱,必填一项,前端自行控制

响应示例

{
  "resultCode":"",
  "resultMsg":"",
  "responseTimestamp":"",
  "status":"",
  "invoiceMaterial":"",
  "invoiceType":"",
  "invoiceNo":"",
  "invoiceCode":"",
  "checkCode":"",
  "cipherCode":"",
  "issueDate":"",
  "deviceNo":"",
  "merchantName":"",
  "merchantId":"",
  "terminalId":"",
  "merOrderId":"",
  "merOrderDate":"",
  "buyerName":"",
  "buyerTaxCode":"",
  "buyerAddress":"",
  "buyerTelephone":"",
  "buyerBank":"",
  "buyerAccount":"",
  "sellerName":"",
  "sellerTaxCode":"",
  "sellerAddress":"",
  "sellerTelphone":"",
  "sellerBank":"",
  "sellerAccount":"",
  "payee":"",
  "checker":"",
  "drawer":"",
  "remark":"",
  "taxMethod":"",
  "deductionAmount":0,
  "totalPriceIncludingTax":0,
  "totalTax":0,
  "totalPrice":0,
  "notifyMobileNo":"",
  "notifyEmail":"",
  "qrCode":"",
  "pdfUrl":""
}

响应参数

名称 类型 必填 最大长度 描述 示例值
resultCode string 64 错误码
resultMsg string 64 错误信息
responseTimestamp string 64 应答时间 yyyy-MM-dd HH:mm:ss
status string 64 PENDING:待开具 ISSUING:开具中 ISSUED:已开具 REVERSING:红冲中 REVERSED:已红冲 CLOSED:已关闭
invoiceMaterial string 64 纸质发票:PAPER 电子发票: ELECTRONIC
invoiceType string 64 普通发票:PLAIN 增值税专用发票:VAT
invoiceNo string 64 发票号码
invoiceCode string 64 发票代码
checkCode string 64 校验码
cipherCode string 64 密码区
issueDate string 64 开票日期
deviceNo string 64 机器编号
merchantName string 64 银商商户名称
merchantId string 64 银商商户号
terminalId string 64 银商终端号
merOrderId string 64 商户订单号
merOrderDate string 64 商户订单日期
buyerName string 64 买方名称
buyerTaxCode string 64 买方纳税人识别号
buyerAddress string 64 买方地址
buyerTelephone string 64 买方电话
buyerBank string 64 买方开户行
buyerAccount string 64 买方银行账号
sellerName string 64 卖方名称
sellerTaxCode string 64 卖方纳税人识别号
sellerAddress string 64 卖方地址
sellerTelphone string 64 卖方电话
sellerBank string 64 卖方开户行
sellerAccount string 64 卖方账号
payee string 64 收款人
checker string 64 复核人
drawer string 64 开票
remark string 64 备注
taxMethod string 64 征税方式
deductionAmount number 64 扣除额
totalPriceIncludingTax number 64 含税总金额
totalTax number 64 税额
totalPrice number 64 不含税总金额
notifyMobileNo string 64 推送短信手机号
notifyEmail string 64 推送 PDF 文件的邮箱
qrCode string 64 领票二维码
pdfUrl string 64 PDF下载链接

错误码