java实现钉钉扫码登录_钉钉扫码登录应用 - qinjiudong的个人空间 - OSCHINA - 中文开源技术交流社区...

$code = $_GET['code'];

$aa = 'https://oapi.dingtalk.com/sns/gettoken?appid=dingodz6n97wis&appsecret=pKy2MnFWMp4sPBTgwGOujWI6rT5QOxS_0pIKyZWREyTSaW2SmyziJgEQ8Dxs0';

$res = file_get_contents($aa);

$arr = json_decode($res,1);

$access_token = $arr['access_token'];

$u = 'https://oapi.dingtalk.com/sns/get_persistent_code?access_token='.$access_token;

$data = array('tmp_auth_code'=>$code);

$str = json_encode($data);

$res1 = getcodes($u,$str);

$arr1 = json_decode($res1,1);

$openid = $arr1['openid'];

$persistent_code = $arr1['persistent_code'];

$data = array('openid'=>$openid,'persistent_code'=>$persistent_code);

$str = json_encode($data);

$u = 'https://oapi.dingtalk.com/sns/get_sns_token?access_token='.$access_token;

$res2 = getcodes($u,$str);

$arr2 = json_decode($res2,1);

$sns_token = $arr2['sns_token'];

$u = 'https://oapi.dingtalk.com/sns/getuserinfo?sns_token='.$sns_token;

$res3 = file_get_contents($u);

echo '

';

print_r(json_decode($res3,1));

function getcodes($remote_server,$post_string){

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, $remote_server);

curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,0);

curl_setopt($ch, CURLOPT_POST, 1);

curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);

curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/json;charset=utf-8']);

curl_setopt($ch, CURLOPT_POSTFIELDS, $post_string);

curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

$data = curl_exec($ch);

curl_close($ch);

return $data;

}

注意:请求https连接,curl参数缺少导致请求失败,post请求必须加头信息说明数据格式,否则返回数据格式不正确

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值