获取钉钉用户信息踩坑

VUE2


跨域问题:

config/index.js
proxyTable: {
  '/base-api': //替换的字符串
  {
    target: 'http://localhost:10087/',
    changeOrigin: true,//跨域申请
    pathRewrite: {
      ["^/base-api"]: "",
    },
  },
},
//跨域链接发起
export function getDingDingUserInfo(data){
    return request({
        url:getBaseUrl('dingding/userInfo'),
        method:'post',
        data
    })
}

钉钉依赖安装:

npm install dingtalk-jsapi --save

前端获取用户信息

dd.ready(()=>{
  dd.runtime.permission.requestAuthCode({
    corpId:process.env.APP_DD_CORP_ID,
    onSuccess:function(res){
      console.log(res.code)
      getDingDingUserInfo({code:res.code})
      .then(res=>{
        console.log(res)
      })
      .catch(res=>{
        console.log(res)
      })
    },
    onFail:function(res){
      console.log(res)
    }
  })
})

服务器访问钉钉

req := &_userIdReq{Code: code}
url := "https://oapi.dingtalk.com/topapi/v2/user/getuserinfo?access_token=" + token
data, err := utils.HttpPost(url, req)

你可能感兴趣的:(html,钉钉,javascript,前端)