# Overview

OpenApi是AsiaBill提供到第三方合作平台，为解决平台运营以及商户数据信息获取的行业解决方案。

## 流程介绍

我们使用[OAuth 2.0](https://tools.ietf.org/html/rfc6749)授权您访问我们的API接口

{% hint style="info" %}
注意需要联系Asiabill客服人员，先在Asiabill添加上您机构的client\_id
{% endhint %}

![授权流程图](https://2777071108-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLUyNA110IhHvQuKkTIYy%2Fuploads%2Fmc56aoWdLt9tqldggyuh%2FOAuth%E6%8E%88%E6%9D%83%E6%B5%81%E7%A8%8B%E5%9B%BE.png?alt=media\&token=d1f95a12-7610-41aa-accc-2a697b7016e0)

### 一、页面获取授权码 <a href="#shou-quan" id="shou-quan"></a>

1.先通过浏览器访问[申请授权码接口](https://asiabill.gitbook.io/openapi/shou-quan-jie-kou#shen-qing-shou-quan-ma)，进行用户授权操作，如果在用户未登录的情况下，会跳转到用户登录页面

![用户登录页面](https://2777071108-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLUyNA110IhHvQuKkTIYy%2Fuploads%2F0i0k6r9sge3O1kj1wZIK%2Fimage.png?alt=media\&token=017eb593-87a4-4fbd-af82-8638c8ab0dd1)

登录信息必须是该商户的超级管理员信息

| 表单字段       | 描述                 |
| ---------- | ------------------ |
| merchantId | 支持商户号和网关号（目前使用商户号） |
| username   | 用户名                |
| password   | 密码                 |

登录完成后会跳转到用户授权界面

<div align="left"><img src="https://2777071108-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLUyNA110IhHvQuKkTIYy%2Fuploads%2FTiYir0hvIKVQ5OmRdQSn%2F%E6%8E%88%E6%9D%83%E6%88%AA%E5%9B%BE.png?alt=media&#x26;token=dd47e1fe-8d86-4f73-9470-c2daf78817b7" alt="用户授权界面"></div>

用户授权后，会跳转到商户设置的 redirect\_uri 路径，并且会带上code参数和商户号，合作伙伴根据商户号去关联code，例如：

![](https://2777071108-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLUyNA110IhHvQuKkTIYy%2Fuploads%2F8opp3XUXqw4Hty31gRnU%2Fimage.png?alt=media\&token=10ca1c53-3548-460b-acb6-e4bbc0b826c5)

redirect\_uri 路径最好是商家服务器接口，商家获取到code后，[获取access\_token](https://asiabill.gitbook.io/openapi/shou-quan-jie-kou#huo-qu-accesstoken)接口成功后，再返回到界面显示成功

### 二、获取access\_token

在上一步获取到code值后，调用[`获取access_token接口`](https://asiabill.gitbook.io/openapi/shou-quan-jie-kou#huo-qu-accesstoken)`，获取到的`access\_token 最好保存起来，目前 access\_token 是长期有效的，建议加密保存，避免泄露

## 开通三方平台账号

请联系 AsiaBill 官方客服，来开通 client\_id 以及设置 client\_secret，并且需要提供商家logo

## 环境地址

### 测试环境

oauthUrl：<https://auth-uat.asiabill.com>

openApiUrl：<https://api-uat.asiabill.com>

### 生产环境

oauthUrl：[https://oauth.asiabill.com](https://auth-sandbox.asiabill.com)

openApiUrl：[https://openapi.asiabill.com](https://api-sandbox.asiabill.com)

## 访问接口请求头

<table><thead><tr><th width="150">请求头字段名</th><th>请求头说明</th></tr></thead><tbody><tr><td>authorization</td><td>access_token，格式：Bearer ACCESS_TOKEN</td></tr><tr><td>request-id</td><td>请求id，30分钟之内唯一</td></tr><tr><td>request-time</td><td>请求时间（格式 yyyy-MM-dd'T'HH:mm:ss ，该时间为当前时间正负30分钟内）</td></tr></tbody></table>
