1.准备条件:
微信小程序并且通过微信认证
2.步骤
1.服务端获取接口调用凭证:access_token
服务端获取接口调用凭证access_token,然后将其返回给前端。
2.小程序授权获取卡包发票列表:官方文档
uni.authorize({
scope: 'scope.invoice',
success(res) {
console.log(res)
uni.chooseInvoice({
success(res) {
console.log(res)
let cardList = JSON.parse(res.invoiceInfo) // 卡包发票列表数据
let card_id = cardList[0].card_id
let encrypt_code = cardList[0].encrypt_code
}
})
}
})
3.通过上述发票列表某一条的card_id、encrypt_code以及access_token获取发票详情,也可以批量获取:官方文档
uni.request({
url: "https://api.weixin.qq.com/card/invoice/reimburse/getinvoiceinfo?access_token=" + access_token,
method: 'POST',
data: {
card_id: card_id,
encrypt_code: encrypt_code
},
success: res => {
console.log("发票详情",res);
},
fail: res => {
console.log(res);
}
})
返回值示例,注意,所有金额字段小数点被省去,真实数据应该为两位小数,示例fee_without_tax真实值应该为:23.45。
{
"errcode": 0,
"errmsg": "ok",
"card_id": "pjZ8Yt5crPbAouhFqFf6JFgZv4Lc",
"begin_time": 1476068114,
"end_time": 1476168114,
"user_card_status": "EXPIRE",
"openid": "obLatjnG4vRXJvSO8p914rSK8-Vo",
"type": "广东省增值税普通发票",
"payee": "测试-收款方",
"detail": "测试-detail",
"user_info": {
"fee": 1100,
"title": "XX公司",
"billing_time": 1468322401,
"billing_no": "hello",
"billing_code": "world",
"info": [
{
"name": "绿巨人",
"num": 10,
"unit": "吨",
"price": 4
}
],
"accept": true,
"fee_without_tax": 2345,
"tax": 123,
"pdf_url": "pdf_url",
" reimburse_status": "INVOICE_REIMBURSE_INIT",
}
}