开发者账号

平台用户注册后系统默认分配app_idapp_secret,使用app_idapp_secret获取开发者身份令牌后,才允许使用平台服务。

开启开发者账号

点击左侧导航栏 平台设置 下的 账户设置 ,进入账户设置页面 在此页面用户可以查看到自己的基本信息,包括app_idapp_secretimage

获取身份令牌

第三方平台使用上一步获取的app_idapp_secret调用获取开发者身份令牌API

linux样例

# 发送开发者身份令牌获取请求
curl -H 'Content-type: application/x-www-form-urlencoded' -XPOST https://baas.qualink.com/bas/oauth/token -d "grant_type=client_credentials&client_id=test01&client_secret=test01secret"
# 得到如下响应
{
    "success": true, 
    "msg": "获取令牌成功", 
    "data"{
        "accessToken":"eyJ0eXBlIjoiSldUIiwiYWxnIjoiSFMyNTYifQ.eyJpc3MiOiJxdWFsaXR5Y2hhaW4iLCJhdWQiOiJ7XCJ0eXBlXCI6XCJcIixcInVjb2RlXCI6XCJcIixcInVpZFwiOlwiMjAxODA1MDQxNDM3NDMzMDgwNzBcIixcInVuYW1lXCI6XCJmb2dyYXlcIn0iLCJzdWIiOiJvdCIsIm5iZiI6MTU3MzI4MTkzNiwiaWF0IjoxNTczMjgxOTM2LCJleHAiOjE1NzMyOTYzMzZ9.O3NK1-TUU84zADhIEWVxSbFqNINI-fjvm6Ic3AX2g64", "jti":"96d145ca-5a3f-4287-9280-139710611733"
    }
}

java样例


import java.util.HashMap;
import java.util.Map;

import com.alibaba.fastjson.JSONObject;
import com.inspur.pub.tool.HttpClientUtil;

public class TestToken {

    private static String testAppId = "appid";//你的appid和appsecret 可以由平台设置下的商户设置查看
    private static String testAppSecret = "appsecret";
    public static Map<String,String> header = new HashMap();
    public static String accessToken = "";

    public TestToken() {
        getNewToken();
    }

    public void getNewToken(){
        String getTokenUrl = "https://baas.qualink.com/bas/oauth/token?grant_type=client_credentials&client_id="+testAppId+
                 "&client_secret="+testAppSecret;
        Map<String, String> getTokenHeader = new HashMap<>();
        getTokenHeader.put("Content-type", "application/x-www-form-urlencoded");

        Map<String, Object> data = new HashMap<>();
        //token即包含身份令牌的响应信息
        String token = HttpClientUtil.httpPost(getTokenUrl, getTokenHeader, data);
        JSONObject jsonObject = JSONObject.parseObject(JSONObject.parseObject(token).getString("data"));
        accessToken = jsonObject.getString("accessToken");
        setHeader(accessToken);
    }

    public void setHeader(String accessToken) {
        this.header.put("Content-type", "application/x-www-form-urlencoded");
        this.header.put("Authorization", accessToken);
    }

    public String httpPost(String url,Map<String,Object> data) {
        String response = HttpClientUtil.httpPost(url, this.header, data);
        if(JSONObject.parseObject(response).getString("success").equals("false")
                &&JSONObject.parseObject(response).getString("msg").equals("身份效验失败")) {
            getNewToken();
            return HttpClientUtil.httpPost(url, this.header, data);
        }else {
            return response;
        }
    }

    public String httpGet(String url) {
        String response = HttpClientUtil.httpGet(url, this.header);
        if(JSONObject.parseObject(response).getString("success").equals("false")
                &&JSONObject.parseObject(response).getString("msg").equals("身份效验失败")) {
            getNewToken();
            return HttpClientUtil.httpGet(url, this.header);
        }else {
            return response;
        }
    }
    public Map<String,String> getHeader(){
        return this.header;
    }

    public String getToken(){
        return this.accessToken;
    }

    public static void main(String[] args) {
        TestToken testToken = new TestToken();
        String url = "https://baas.qualink.com/bas/chain/user/info";
        String res = testToken.httpGet(url);
        System.out.println(res);
    }

}

这样,开发者就可以使用accessToken调用平台其他服务了。