github.com/fastwego/offiaccount@v1.0.1/apis/invoice/invoice.go (about) 1 // Copyright 2020 FastWeGo 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 // Package invoice 微信发票 16 package invoice 17 18 import ( 19 "bytes" 20 21 "github.com/fastwego/offiaccount" 22 ) 23 24 const ( 25 apiGetAuthUrl = "/card/invoice/getauthurl" 26 apiGetAuthData = "/card/invoice/getauthdata" 27 apiRejectInsert = "/card/invoice/rejectinsert" 28 apiMakeOutInvoice = "/card/invoice/makeoutinvoice" 29 apiClearOutInvoice = "/card/invoice/clearoutinvoice" 30 apiQueryInvoceInfo = "/card/invoice/queryinvoceinfo" 31 apiSetUrl = "/card/invoice/seturl" 32 apiPlatformCreateCard = "/card/invoice/platform/createcard" 33 apiPlatformSetpdf = "/card/invoice/platform/setpdf" 34 apiPlatformGetpdf = "/card/invoice/platform/getpdf" 35 apiInsert = "/card/invoice/insert" 36 apiPlatformUpdateStatus = "/card/invoice/platform/updatestatus" 37 apiReimburseGetInvoiceInfo = "/card/invoice/reimburse/getinvoiceinfo" 38 apiReimburseGetInvoiceBatch = "/card/invoice/reimburse/getinvoicebatch" 39 apiReimburseUpdateInvoiceStatus = "/card/invoice/reimburse/updateinvoicestatus" 40 apiReimburseUpdateStatusBatch = "/card/invoice/reimburse/updatestatusbatch" 41 apiGetUserTitleUrl = "/card/invoice/biz/getusertitleurl" 42 apiGetSelectTitleUrl = "/card/invoice/biz/getselecttitleurl" 43 apiScanTitle = "/card/invoice/scantitle" 44 ) 45 46 /* 47 获取授权页链接 48 49 本接口供商户调用。商户通过本接口传入订单号、开票平台标识等参数,获取授权页的链接。在微信中向用户展示授权页,当用户点击了授权页上的“领取发票”/“申请开票”按钮后,即完成了订单号与该用户的授权关系绑定,后续开票平台可凭此订单号发起将发票卡券插入用户卡包的请求,微信也将据此授权关系校验是否放行插卡请求 50 51 See: https://developers.weixin.qq.com/doc/offiaccount/WeChat_Invoice/E_Invoice/Vendor_API_List.html 52 53 POST https://api.weixin.qq.com/card/invoice/getauthurl?access_token={access_token} 54 */ 55 func GetAuthUrl(ctx *offiaccount.OffiAccount, payload []byte) (resp []byte, err error) { 56 return ctx.Client.HTTPPost(apiGetAuthUrl, bytes.NewReader(payload), "application/json;charset=utf-8") 57 } 58 59 /* 60 查询授权完成状态 61 62 63 64 See: https://developers.weixin.qq.com/doc/offiaccount/WeChat_Invoice/E_Invoice/Vendor_API_List.html 65 66 POST https://api.weixin.qq.com/card/invoice/getauthdata?access_token={access_token} 67 */ 68 func GetAuthData(ctx *offiaccount.OffiAccount, payload []byte) (resp []byte, err error) { 69 return ctx.Client.HTTPPost(apiGetAuthData, bytes.NewReader(payload), "application/json;charset=utf-8") 70 } 71 72 /* 73 拒绝开票 74 75 户完成授权后,商户若发现用户提交信息错误、或者发生了退款时,可以调用该接口拒绝开票并告知用户。拒绝开票后,该订单无法向用户再次开票。已经拒绝开票的订单,无法再次使用,如果要重新开票,需使用新的order_id,获取授权链接,让用户再次授权 76 77 See: https://developers.weixin.qq.com/doc/offiaccount/WeChat_Invoice/E_Invoice/Vendor_API_List.html 78 79 POST https://api.weixin.qq.com/card/invoice/rejectinsert?access_token={access_token} 80 */ 81 func RejectInsert(ctx *offiaccount.OffiAccount, payload []byte) (resp []byte, err error) { 82 return ctx.Client.HTTPPost(apiRejectInsert, bytes.NewReader(payload), "application/json;charset=utf-8") 83 } 84 85 /* 86 统一开票接口-开具蓝票 87 88 对于使用微信电子发票开票接入能力的商户,在公众号后台选择任何一家开票平台的套餐,都可以使用本接口实现电子发票的开具 89 90 See: https://developers.weixin.qq.com/doc/offiaccount/WeChat_Invoice/E_Invoice/Vendor_API_List.html 91 92 POST https://api.weixin.qq.com/card/invoice/makeoutinvoice?access_token={access_token} 93 */ 94 func MakeOutInvoice(ctx *offiaccount.OffiAccount, payload []byte) (resp []byte, err error) { 95 return ctx.Client.HTTPPost(apiMakeOutInvoice, bytes.NewReader(payload), "application/json;charset=utf-8") 96 } 97 98 /* 99 统一开票接口-发票冲红 100 101 对于使用微信电子发票开票接入能力的商户,在公众号后台选择任何一家开票平台的套餐,都可以使用本接口实现电子发票的冲红 102 103 See: https://developers.weixin.qq.com/doc/offiaccount/WeChat_Invoice/E_Invoice/Vendor_API_List.html 104 105 POST https://api.weixin.qq.com/card/invoice/clearoutinvoice?access_token={access_token} 106 */ 107 func ClearOutInvoice(ctx *offiaccount.OffiAccount, payload []byte) (resp []byte, err error) { 108 return ctx.Client.HTTPPost(apiClearOutInvoice, bytes.NewReader(payload), "application/json;charset=utf-8") 109 } 110 111 /* 112 统一开票接口-查询已开发票 113 114 对于使用微信电子发票开票接入能力的商户,在公众号后台选择任何一家开票平台的套餐,都可以使用本接口实现已开具电子发票的查询 115 116 See: https://developers.weixin.qq.com/doc/offiaccount/WeChat_Invoice/E_Invoice/Vendor_API_List.html 117 118 POST https://api.weixin.qq.com/card/invoice/queryinvoceinfo?access_token={access_token} 119 */ 120 func QueryInvoceInfo(ctx *offiaccount.OffiAccount, payload []byte) (resp []byte, err error) { 121 return ctx.Client.HTTPPost(apiQueryInvoceInfo, bytes.NewReader(payload), "application/json;charset=utf-8") 122 } 123 124 /* 125 获取自身的开票平台识别码 126 127 开票平台可以通过此接口获得本开票平台的预开票url,进而获取s_pappid。开票平台将该s_pappid并透传给商户,商户可以通过该s_pappid参数在微信电子发票方案中标识出为自身提供开票服务的开票平台 128 129 See: https://developers.weixin.qq.com/doc/offiaccount/WeChat_Invoice/E_Invoice/Invoicing_Platform_API_List.html 130 131 POST https://api.weixin.qq.com/card/invoice/seturl?access_token={access_token} 132 */ 133 func SetUrl(ctx *offiaccount.OffiAccount, payload []byte) (resp []byte, err error) { 134 return ctx.Client.HTTPPost(apiSetUrl, bytes.NewReader(payload), "application/json;charset=utf-8") 135 } 136 137 /* 138 创建发票卡券模板 139 140 通过本接口可以为创建一个商户的发票卡券模板,为该商户配置发票卡券模板上的自定义栏位。创建发票卡券模板生成的card_id将在创建发票卡券时被引用,故创建发票卡券模板是创建发票卡券的基础 141 142 See: https://developers.weixin.qq.com/doc/offiaccount/WeChat_Invoice/E_Invoice/Invoicing_Platform_API_List.html 143 144 POST https://api.weixin.qq.com/card/invoice/platform/createcard?access_token={access_token} 145 */ 146 func PlatformCreateCard(ctx *offiaccount.OffiAccount, payload []byte) (resp []byte, err error) { 147 return ctx.Client.HTTPPost(apiPlatformCreateCard, bytes.NewReader(payload), "application/json;charset=utf-8") 148 } 149 150 /* 151 上传PDF 152 153 商户或开票平台可以通过该接口上传PDF。PDF上传成功后将获得发票文件的标识,后续可以通过插卡接口将PDF关联到用户的发票卡券上,一并插入到收票用户的卡包中 154 155 See: https://developers.weixin.qq.com/doc/offiaccount/WeChat_Invoice/E_Invoice/Invoicing_Platform_API_List.html 156 157 POST https://api.weixin.qq.com/card/invoice/platform/setpdf?access_token={access_token} 158 */ 159 func PlatformSetpdf(ctx *offiaccount.OffiAccount, payload []byte) (resp []byte, err error) { 160 return ctx.Client.HTTPPost(apiPlatformSetpdf, bytes.NewReader(payload), "application/json;charset=utf-8") 161 } 162 163 /* 164 查询已上传的PDF文件 165 166 用于供发票PDF的上传方查询已经上传的发票或消费凭证PDF 167 168 See: https://developers.weixin.qq.com/doc/offiaccount/WeChat_Invoice/E_Invoice/Invoicing_Platform_API_List.html 169 170 POST https://api.weixin.qq.com/card/invoice/platform/getpdf?action=get_url&access_token={access_token} 171 */ 172 func PlatformGetpdf(ctx *offiaccount.OffiAccount, payload []byte) (resp []byte, err error) { 173 return ctx.Client.HTTPPost(apiPlatformGetpdf, bytes.NewReader(payload), "application/json;charset=utf-8") 174 } 175 176 /* 177 将电子发票卡券插入用户卡包 178 179 本接口由开票平台或自建平台商户调用。对用户已经授权过的开票请求,开票平台可以使用本接口将发票制成发票卡券放入用户的微信卡包中 180 181 See: https://developers.weixin.qq.com/doc/offiaccount/WeChat_Invoice/E_Invoice/Invoicing_Platform_API_List.html 182 183 POST https://api.weixin.qq.com/card/invoice/insert?access_token={access_token} 184 */ 185 func Insert(ctx *offiaccount.OffiAccount, payload []byte) (resp []byte, err error) { 186 return ctx.Client.HTTPPost(apiInsert, bytes.NewReader(payload), "application/json;charset=utf-8") 187 } 188 189 /* 190 更新发票卡券状态 191 192 193 194 See: https://developers.weixin.qq.com/doc/offiaccount/WeChat_Invoice/E_Invoice/Invoicing_Platform_API_List.html 195 196 POST https://api.weixin.qq.com/card/invoice/platform/updatestatus?access_token={access_token} 197 */ 198 func PlatformUpdateStatus(ctx *offiaccount.OffiAccount, payload []byte) (resp []byte, err error) { 199 return ctx.Client.HTTPPost(apiPlatformUpdateStatus, bytes.NewReader(payload), "application/json;charset=utf-8") 200 } 201 202 /* 203 查询报销发票信息 204 205 通过该接口查询电子发票的结构化信息,并获取发票PDF文件 206 207 See: https://developers.weixin.qq.com/doc/offiaccount/WeChat_Invoice/E_Invoice/Reimburser_API_List.html 208 209 POST https://api.weixin.qq.com/card/invoice/reimburse/getinvoiceinfo?access_token={access_token} 210 */ 211 func ReimburseGetInvoiceInfo(ctx *offiaccount.OffiAccount, payload []byte) (resp []byte, err error) { 212 return ctx.Client.HTTPPost(apiReimburseGetInvoiceInfo, bytes.NewReader(payload), "application/json;charset=utf-8") 213 } 214 215 /* 216 批量查询报销发票信息 217 218 219 220 See: https://developers.weixin.qq.com/doc/offiaccount/WeChat_Invoice/E_Invoice/Reimburser_API_List.html 221 222 POST https://api.weixin.qq.com/card/invoice/reimburse/getinvoicebatch?access_token={access_token} 223 */ 224 func ReimburseGetInvoiceBatch(ctx *offiaccount.OffiAccount, payload []byte) (resp []byte, err error) { 225 return ctx.Client.HTTPPost(apiReimburseGetInvoiceBatch, bytes.NewReader(payload), "application/json;charset=utf-8") 226 } 227 228 /* 229 报销方更新发票状态 230 231 232 233 See: https://developers.weixin.qq.com/doc/offiaccount/WeChat_Invoice/E_Invoice/Reimburser_API_List.html 234 235 POST https://api.weixin.qq.com/card/invoice/reimburse/updateinvoicestatus?access_token={access_token} 236 */ 237 func ReimburseUpdateInvoiceStatus(ctx *offiaccount.OffiAccount, payload []byte) (resp []byte, err error) { 238 return ctx.Client.HTTPPost(apiReimburseUpdateInvoiceStatus, bytes.NewReader(payload), "application/json;charset=utf-8") 239 } 240 241 /* 242 报销方批量更新发票状态 243 244 245 246 See: https://developers.weixin.qq.com/doc/offiaccount/WeChat_Invoice/E_Invoice/Reimburser_API_List.html 247 248 POST https://api.weixin.qq.com/card/invoice/reimburse/updatestatusbatch?access_token={access_token} 249 */ 250 func ReimburseUpdateStatusBatch(ctx *offiaccount.OffiAccount, payload []byte) (resp []byte, err error) { 251 return ctx.Client.HTTPPost(apiReimburseUpdateStatusBatch, bytes.NewReader(payload), "application/json;charset=utf-8") 252 } 253 254 /* 255 将发票抬头信息录入到用户微信中 256 257 调用接口,获取添加存储发票抬头信息的链接,将链接发给微信用户,用户确认后将保存该信息 258 259 See: https://developers.weixin.qq.com/doc/offiaccount/WeChat_Invoice/Quick_issuing/Interface_Instructions.html 260 261 POST https://api.weixin.qq.com/card/invoice/biz/getusertitleurl?access_token={access_token 262 */ 263 func GetUserTitleUrl(ctx *offiaccount.OffiAccount, payload []byte) (resp []byte, err error) { 264 return ctx.Client.HTTPPost(apiGetUserTitleUrl, bytes.NewReader(payload), "application/json;charset=utf-8") 265 } 266 267 /* 268 获取用户抬头(方式一):获取商户专属二维码,立在收银台 269 270 商户调用接口,获取链接,将链接转成二维码,用户扫码,可以选择抬头发给商户 271 272 See: https://developers.weixin.qq.com/doc/offiaccount/WeChat_Invoice/Quick_issuing/Interface_Instructions.html 273 274 POST https://api.weixin.qq.com/card/invoice/biz/getselecttitleurl?access_token={access_token} 275 */ 276 func GetSelectTitleUrl(ctx *offiaccount.OffiAccount, payload []byte) (resp []byte, err error) { 277 return ctx.Client.HTTPPost(apiGetSelectTitleUrl, bytes.NewReader(payload), "application/json;charset=utf-8") 278 } 279 280 /* 281 获取用户抬头(方式二):商户扫描用户的发票抬头二维码 282 283 商户扫用户“我的—个人信息—我的发票抬头”里面的抬头二维码后,通过调用本接口,可以获取用户抬头信息 284 285 See: https://developers.weixin.qq.com/doc/offiaccount/WeChat_Invoice/Quick_issuing/Interface_Instructions.html 286 287 POST https://api.weixin.qq.com/card/invoice/scantitle?access_token={access_token} 288 */ 289 func ScanTitle(ctx *offiaccount.OffiAccount, payload []byte) (resp []byte, err error) { 290 return ctx.Client.HTTPPost(apiScanTitle, bytes.NewReader(payload), "application/json;charset=utf-8") 291 }