• 尊时凯龙

    shopee open v2授权方法

    2021/04/21

    v2授权教学

    v2授权网址组成说明       

    返回内容




    字段

    类型

    必要

    说明

    code

    string

    Yes

    用于获取access_token和refresh_token。一次性使用有效期为10分钟。

    Shop_id

    int

    yes

    完成授权的shop_id

     

    开发人员按照以下规则生成授权链接,连结提供给卖场营运人员进行授权。授权完毕后即可透过API对店铺进行操作。取消授权作法流程同卖场授权流程。

    取消授权网址


    https://partner.shopeemobile.com/api/v2/shop/cancel_auth_partner

    正式环境

    https://partner.uat.shopeemobile.com/api/v2/shop/cancel_auth_partner

    测试环境

     

    授权使用参数




    字段

    类型

    必要

    说明

    partner_id

     

    Int

    yes

    Partner ID可点选右上角console后选择APP,则可在APP List中查看

    Redirect

    String

    yes

    仅在授权成功后导向的页面,可以使用任何网址

    (e.g.公司网站、卖场网址)

    Sign

    String

    yes

    依Shopee规则产生的字符串

    timestampt

    int

    yes

    需要与sign字符串使用的时间戳保持一致。 5分钟后过期。

     

    v2授权网址组成范例

    本部分说明如何生成用于卖场授权的HMAC-SHA256。

    v2授权网址组成步骤

    1.    组成sign的规则

    10090/api/v2/shop/auth_partner1594897040

    按照此顺序,以partner_id ,api path ,timestamp组成sign。

    2.    加密字符串

    依上一步骤将字符串结合后需要透过SHA256 hashing algorithm(HMAC)加密,加密后则为Token。加密后范例如下:

    90c12d3932f3826f0c72242e1ec6492eec9a1298658f41f7a9469664801c4e5a

    3.    组成授权网址

     

    接着按照上述"授权网址组成范例"的规则组成授权网址

    4.    完成授权

    https://www.baidu.com/?code=xxxxxxxxxx&shop_id=xxxxxx

    依照上述网址完成卖场授权后,将重新导至此网址:(xxx表示随机或以该卖场shop id为主)

     

    v2授权逾时逻辑

    授权网址会在5分钟内过期(因为Timestamp过期),所以开发人员必须重新生成一个新的授权网址。

    若进入授权网址后,未在3分钟内登入卖场账号、密码,将会得到错误讯息"operation overtime",需要重新进入卖场授权网址,而不是重新整理该页面。

     

    v2验证请求说明

    除非指定对某些特定的API使用HTTP / FORM(在API文檔中有说明),否则对所有其余的API使用HTTP / JSON。

    以下教学同OpenAPI 2.0 Authorization & Authentication。

    使用参数




    字段

    类型

    必要

    说明

    partner_id

    Int

    yes

    Partner ID可点选右上角console后选择APP,则可在APP List中查看

    timestamp

    Int

    Yes

    所有请求都必须包含。 5分钟后过期

    access_token

    String

    No

        将access_token用作某些API的通用请求参数, 在过期前可以多次使用,有效期为4小时

    要调用Get Access_token API和刷新Access_token   API,可以跳过此参数

    sign

    String

    Yes

    依Shopee规则产生的字符串

     

    shop_id

     

    int

    No


     

    返回内容




    字段

    类型

    必要

    说明

    request_id

    string

    Yes

    用于提供给Shopee查询呼叫纪录

    error

    string

    Yes

    错误讯息,若无错误则返回空值

    message

    string

    No


    response

    object

    no

    详细错误讯息说明

     

    Step1、建立签名基本字符串

    本部分说明如何为API请求用的验证生成HMAC-SHA256。

    按照此顺序,使用partner_id ,api path ,timestamp ,access_token 和shop_id 组成sign(要调用Get Access_token API和Refresh Access_token API,可以在符号基础字符串中跳过access_token)。

     

    Step2、签名加密

    将Sign和Partner key以HMAC-SHA256 hashing algorithm来加密。

     

    Get Access_token

    API: https://partner.shopeemobile.com/api/v2/auth/token/get Method: Post

    Description: 使用此API和代码来获取access_token和refresh_token。

    使用参数




    字段

    类型

    必要

    说明

    code

    String

    yes

    卖场授权后,重新导向URL中的代码。为一次性使用,有效期为10分钟

    partner_id

    Int

    Yes

    开发者APP的Partner id

    shop_id

    int

    Yes

    卖场Shop id

     

    返回内容




    字段

    类型

    必要

    说明

    request_id

    string

    yes

    用于提供给Shopee查询呼叫

    error

    string

    yes

    纪录错误讯息,若无错误则返回空值

    refresh_token

    string

    yes

    使用refresh_token获取新的access_token。一次

    access_token

    string

    yes

    将access_token用作某些API的通用请求参数。有效多次使用,有效期为4小时

    expire_in

    int

    yes

    access_token过期时间,单位为秒

     

    Refresh Access_token

    API: https://partner.shopeemobile.com/api/v2/auth/access_token/get Method: Post

    Description: 使用此API和代码来重新获取access_token当access_token过期后。

    使用参数




    字段

    类型

    必要

    说明

    refresh_token

    string

    Yes

    使用refresh_token获取新的access_token。一次性使用,有效期为30天。

    partner_id

    Int

    Yes

    开发者APP的Partner id

    shop_id

    Int

    Yes

    卖场Shop id

     

    返回内容




    字段

    类型

    必要

    说明

    request_id

    string

    Yes

    用于提供给Shopee查询呼叫纪录

    error

    string

    Yes

    错误讯息,若无错误则返回空值

    refresh_token

    string

    Yes

    使用refresh_token获取新的access_token。一次性使用,有效期为30天

    access_token

    string

    Yes

    将access_token用作某些API的通用请求参数。有效多次使用,有效期为4小时

    expire_in

    Int

    Yes

    access_token过期时间,单位为秒

    partner_id

    Int

    Yes

    开发者APP的Partner id

    shop_id

    Int

    Yes

    卖场Shop id

     

    取得Shop ID方法

    授权后欲查看Shop ID可参考以下方法:

    ●   一经卖家授权完成后,开发者的信箱将会收到授权通知信,信件内部将提及Shop ID。(测试环境不

    ●   Shop ID将会出现在授权完成后跳转的页面网址中,例如在组成卖家授权网址时,填入Redirect Url为https://www.google.com/,则一经授权网址则会加上Shop ID,如下图所示:

    ●   如果启用了Webhook功能,JSON消息将被推送到开发者的Callback URL。(测试环境不支持)

    ●   可透过shopee.public.GetShopsByPartner获取该Partner id下的所有Shop id。

     

    shopee官网原文详情:

    v2授權教學

    v2授權網址組成說明       

    返回內容




    欄位

    類型

    必要

    說明

    code

    string

    Yes

    用於獲取access_token和refresh_token。一次性使用有效期為10分鐘。

    Shop_id

    int

    yes

    完成授權的shop_id

     

    開發人員按照以下規則生成授權連結,連結提供給賣場營運人員進行授權。授權完畢後即可透過API對店鋪進行操作。取消授權作法流程同賣場授權流程。

    取消授權網址


    https://partner.shopeemobile.com/api/v2/shop/cancel_auth_partner

    正式環境

    https://partner.uat.shopeemobile.com/api/v2/shop/cancel_auth_partner

    測試環境

     

    授權使用參數




    欄位

    類型

    必要

    說明

    partner_id

     

    Int

    yes

    Partner ID可點選右上角console後選擇APP,則可在APP List中查看

    Redirect

    String

    yes

    僅在授權成功後導向的頁面,可以使用任何網址

    (e.g.公司網站、賣場網址)

    Sign

    String

    yes

    依Shopee規則產生的字串

    timestampt

    int

    yes

    需要與sign字串使用的時間戳記保持一致。 5分鐘後過期。

     

    v2授權網址組成範例

    本部分說明如何生成用於賣場授權的HMAC-SHA256。

    v2授權網址組成步驟

    1.    組成sign的規則

    10090/api/v2/shop/auth_partner1594897040

    按照此順序,以partner_id ,api path ,timestamp組成sign。

    2.    加密字串

    依上一步驟將字串結合後需要透過SHA256 hashing algorithm(HMAC)加密,加密後則為Token。加密後範例如下:

    90c12d3932f3826f0c72242e1ec6492eec9a1298658f41f7a9469664801c4e5a

    3.    組成授權網址

     

    接著按照上述"授權網址組成範例"的規則組成授權網址

    4.    完成授權

    https://www.baidu.com/?code=xxxxxxxxxx&shop_id=xxxxxx

    依照上述網址完成賣場授權後,將重新導至此網址:(xxx表示隨機或以該賣場shop id為主)

     

    v2授權逾時邏輯

    授權網址會在5分鐘內過期(因為Timestamp過期),所以開發人員必須重新生成一個新的授權網址。

    若進入授權網址後,未在3分鐘內登入賣場帳號、密碼,將會得到錯誤訊息"operation overtime",需要重新進入賣場授權網址,而不是重新整理該頁面。

     

    v2驗證請求說明

    除非指定對某些特定的API使用HTTP / FORM(在API文檔中有說明),否則對所有其餘的API使用HTTP / JSON。

    以下教學同OpenAPI 2.0 Authorization & Authentication。

    使用參數




    欄位

    類型

    必要

    說明

    partner_id

    Int

    yes

    Partner   ID可點選右上角console後選擇APP,則可在APP List中查看

    timestamp

    Int

    Yes

    所有請求都必須包含。 5分鐘後過期

    access_token

    String

    No

        將access_token用作某些API的通用請求參數, 在過期前可以多次使用,有效期為4小時

    要調用Get Access_token API和刷新Access_token API,可以跳過此參數

    sign

    String

    Yes

    依Shopee規則產生的字串

     

    shop_id

     

    int

    No


     

    返回內容




    欄位

    類型

    必要

    說明

    request_id

    string

    Yes

    用於提供給Shopee查詢呼叫紀錄

    error

    string

    Yes

    錯誤訊息,若無錯誤則返回空值

    message

    string

    No


    response

    object

    no

    詳細錯誤訊息說明

     

    Step1、建立簽名基底字元串

    本部分說明如何為API請求用的驗證生成HMAC-SHA256。

    按照此順序,使用partner_id ,api path ,timestamp ,access_token 和shop_id 組成sign(要調用Get Access_token API和Refresh Access_token API,可以在符號基礎字串中跳過access_token)。

     

    Step2、簽名加密

    將Sign和Partner key以HMAC-SHA256 hashing algorithm來加密。

     

    Get Access_token

    API: https://partner.shopeemobile.com/api/v2/auth/token/get Method: Post

    Description: 使用此API和代碼來獲取access_token和refresh_token。

    使用參數




    欄位

    類型

    必要

    說明

    code

    String

    yes

    賣場授權後,重新導向URL中的代碼。為一次性使用,有效期為10分鐘

    partner_id

    Int

    Yes

    開發者APP的Partner id

    shop_id

    int

    Yes

    賣場Shop id

     

    返回內容




    欄位

    類型

    必要

    說明

    request_id

    string

    yes

    用於提供給Shopee查詢呼叫

    error

    string

    yes

    紀錄錯誤訊息,若無錯誤則返回空值

    refresh_token

    string

    yes

    使用refresh_token獲取新的access_token。一次

    access_token

    string

    yes

    將access_token用作某些API的通用請求參數。有效多次使用,有效期為4小時

    expire_in

    int

    yes

    access_token過期時間,單位為秒

     

    Refresh Access_token

    API: https://partner.shopeemobile.com/api/v2/auth/access_token/get Method: Post

    Description: 使用此API和代碼來重新獲取access_token當access_token過期後。

    使用參數




    欄位

    類型

    必要

    說明

    refresh_token

    string

    Yes

    使用refresh_token獲取新的access_token。一次性使用,有效期為30天。

    partner_id

    Int

    Yes

    開發者APP的Partner id

    shop_id

    Int

    Yes

    賣場Shop id

     

    返回內容




    欄位

    類型

    必要

    說明

    request_id

    string

    Yes

    用於提供給Shopee查詢呼叫紀錄

    error

    string

    Yes

    錯誤訊息,若無錯誤則返回空值

    refresh_token

    string

    Yes

    使用refresh_token獲取新的access_token。一次性使用,有效期為30天

    access_token

    string

    Yes

    將access_token用作某些API的通用請求參數。有效多次使用,有效期為4小時

    expire_in

    Int

    Yes

    access_token過期時間,單位為秒

    partner_id

    Int

    Yes

    開發者APP的Partner id

    shop_id

    Int

    Yes

    賣場Shop id

     

    取得Shop ID方法

    授權後欲查看Shop ID可參考以下方法:

    ●   一經賣家授權完成後,開發者的信箱將會收到授權通知信,信件內部將提及Shop ID。(測試環境不

    ●   Shop ID將會出現在授權完成後跳轉的頁面網址中,例如在組成賣家授權網址時,填入Redirect Url為https://www.google.com/,則一經授權網址則會加上Shop ID,如下圖所示:

    ●   如果啟用了Webhook功能,JSON消息將被推送到開發者的Callback URL。(測試環境不支援)

    ●   可透過shopee.public.GetShopsByPartner獲取該Partner id下的所有Shop id。

     

    文章来源:shopee官方网站

    更多