1. 程式人生 > >微信小程式 wx.request 獲取百度API token

微信小程式 wx.request 獲取百度API token

wx.request({
        url: "https://aip.baidubce.com/oauth/2.0/token",
        data: {
          grant_type: "client_credentials",
          client_id: config.Config.baiduApiKey,
          client_secret: config.Config.baiduApiSecret
        },
        header:{
          "content-type": "application/x-www-form-urlencoded" 
        },
        success:function(res){
          console.log(res.data)
        }
      })


res返回資料例子:

{
    "access_token": "1.a6b7dbd428f731035f771b8d15063f61.86400.1292922000-2346678-124328",
    "expires_in": 86400,
    "refresh_token": "2.385d55f8615fdfd9edb7c4b5ebdc3e39.604800.1293440400-2346678-124328",
    "scope": "basic email",
    "session_key": "ANXxSNjwQDugf8615OnqeikRMu2bKaXCdlLxn",
    "session_secret": "248APxvxjCZ0VEC43EYrvxqaK4oZExMB",
}