阿里巴巴 API对接 refreshToken换取accessToken的实现

来源:互联网 发布:阿里云dns解析怎么用 编辑:程序博客网 时间:2024/06/06 02:26

http://gw.api.alibaba.com/isv/doc.htm 阿里巴巴开发文档

http://authhz.alibaba.com/dev/tools/auth_test.html  阿里巴巴授权测试

https://login.alibaba.com/?done=http%3A%2F%2Fgw.api.alibaba.com%2Fisv%2Fisv_registry.htm%3Fspm%3D5261.6677069.853074521.5阿里开发者申请

众所周知,阿里巴巴速卖通的店铺授权绑定需要用refreshToken换取accessToken来取得店铺订单,refreshToken有效期半年,accessToken有效期10小时,如何实现通过refreshToken换取accessToken呢?我写了一个例子给大家:

注:我的APPKEY:1621426,签名串:Xccwd561CFi,

我已经获取好的refresh_token:075aa78b-30bf-4a80-802b-00bd9d1cba05

client_id就是APPKEY,client_secret就是签名串

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<title>通过refresh_token获取access_token:</title>

</head>

<body>

<FORM METHOD="post" ACTION="https://gw.api.alibaba.com/openapi/param2/1/system.oauth2/getToken/1621426?grant_type=refresh_token&refresh_token=075aa78b-30bf-4a80-802b-00bd9d1cba05&client_id=1621426&client_secret=Xccwd561CFi">

    <input type="submit" name="button2" value="获取access_token">

  </FORM>

</body>

</html>

无错误则返回如图所示 得到accessToken



注:此接口必须使用POST方法提交;必须使用httpsa) 此处grant_type参数必须为refresh_token,表示通过refreshToken换取accessToken,而不是通过临时code换取b) 调用getToken接口时不需要签名

特别感谢:http://www.cnblogs.com/hesitation/p/4099318.html

感谢google搜索引擎,感谢杨仕海同学,王永斌同学的热心帮助!

0 0
原创粉丝点击