Commit d0a0587a authored by zhoujun's avatar zhoujun

调试钉钉

parent b682c964
......@@ -31,10 +31,11 @@ class UserController extends BaseController
*/
public function getLogin(Request $request)
{
$key = env('dingoap7dwt39svqfxlnkx');
$redirectUri = env('dingoap7dwt39svqfxlnkx');
$url = 'https://oapi.dingtalk.com/connect/qrconnect?appid='.$key.'&response_type=code&scope=snsapi_login&state=STATE&redirect_uri='.$redirectUri;
return redirect($url);
return view('login.index', []);
//$key = env('DD_APP_KEY');
//$redirectUri = env('REDIRECT_URL');
//$url = 'https://oapi.dingtalk.com/connect/qrconnect?appid='.$key.'&response_type=code&scope=snsapi_login&state=STATE&redirect_uri='.$redirectUri;
//return redirect($url);
}
/**
......@@ -46,71 +47,25 @@ class UserController extends BaseController
public function getReturnLogin(Request $request)
{
$Input = $request->all();
$accessKey = env('DD_APP_SECRET');
$timestamp = $this->getmTime();
$signature = $this->getsignature($timestamp,$accessKey);
$url = 'https://oapi.dingtalk.com/sns/getuserinfo_bycode?accessKey=' . $accessKey . '&timestamp=' . $timestamp . '&signature=' . $signature;
$data = [ 'tmp_auth_code' => $Input['code'] ];
$userInfo = $this->curl_json($url, $data);
$res = json_decode($userInfo, true);
print_r($res);die();
if(isset($res['errcode']) and $res['errcode'] == 0) {
}
}
print_r($Input);
// include "TopSdk.php";
// $c = new DingTalkClient(DingTalkConstant::$CALL_TYPE_OAPI, DingTalkConstant::$METHOD_POST , DingTalkConstant::$FORMAT_JSON);
// $req = new OapiSnsGetuserinfoBycodeRequest;
// $req->setTmpAuthCode("4a2c5695b78738d495f47b5fee9160cd");
// $resp=$c->executeWithAccessKey($req, "https://oapi.dingtalk.com/sns/getuserinfo_bycode","yourAppId","yourAppSecret");
// var_dump($resp);
/**
* 计算签名
* @param $timestamp
* @return string
*/
public function getsignature($timestamp,$accessKey)
{
// 根据timestamp, appSecret计算签名值
$s = hash_hmac('sha256', $timestamp, $accessKey, true);
$signature = base64_encode($s);
$urlEncode_signature = urlencode($signature);
return $urlEncode_signature;
}
/**
* 毫秒级时间戳
* @return float
*/
public function getmTime()
{
list($s1, $s2) = explode(' ', microtime());
$mTime = (float)sprintf('%.0f', (floatval($s1) + floatval($s2)) * 1000);
return $mTime;
public function test(){
include "TopSdk.php";
$c = new DingTalkClient(DingTalkConstant::$CALL_TYPE_OAPI, DingTalkConstant::$METHOD_POST , DingTalkConstant::$FORMAT_JSON);
$req = new OapiSnsGetuserinfoBycodeRequest;
$req->setTmpAuthCode("4a2c5695b78738d495f47b5fee9160cd");
$resp=$c->executeWithAccessKey($req, "https://oapi.dingtalk.com/sns/getuserinfo_bycode","yourAppId","yourAppSecret");
var_dump($resp);
}
public function curl_json($url, $postFields = null)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_FAILONERROR, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_USERAGENT, "dingtalk-sdk-php");
//https 请求
if(strlen($url) > 5 && strtolower(substr($url, 0, 5)) == "https") {
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
}
curl_setopt($ch, CURLOPT_POST, true);
$header = [ "Content-Type: application/json; charset=utf-8", "Content-Length:" . strlen(json_encode($postFields)) ];
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($postFields));
$reponse = curl_exec($ch);
if(curl_errno($ch)) {
throw new Exception(curl_error($ch), 0);
} else {
$httpStatusCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
if(200 !== $httpStatusCode) {
throw new Exception($reponse, $httpStatusCode);
}
}
curl_close($ch);
return $reponse;
}
/**
* 用户登出
* @return array
......
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
<title>apk管理</title>
<link rel="icon" type="image/png" sizes="192x192" href="">
<style type="text/css">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>apk文件包上传</title>
<style>
ul {
width: 300px;
}
img {
display: block;
width: 100%;
height: 300px;
margin-bottom: 20px;
}
#login_container{
margin: 200px auto;
width: 400px;
}
</style>
<script src="https://g.alicdn.com/dingding/dinglogin/0.0.5/ddLogin.js"></script>
</head>
<body>
<div id="login_container" style="width: 400px; margin:200px auto;"></div>
<script src="https://g.alicdn.com/dingding/dinglogin/0.0.5/ddLogin.js"></script>
<div id="login_container"></div>
<script>
var url = encodeURIComponent('http://upload-apk.srccwl.com/return/login');
var goto = encodeURIComponent('https://oapi.dingtalk.com/connect/oauth2/sns_authorize?appid=dingoap7dwt39svqfxlnkx &response_type=code&scope=snsapi_login&state=STATE&redirect_uri='+url);
let url = encodeURIComponent('http://upload-apk.srccwl.com/return/login');
let goto = encodeURIComponent('https://oapi.dingtalk.com/connect/oauth2/sns_authorize?appid=dingoap7dwt39svqfxlnkx&response_type=code&scope=snsapi_login&state=STATE&redirect_uri='+url)
DDLogin({
id:"login_container",
goto: goto,
style: "border:none;background-color:#FFFFFF;",
width : "322",
height: "320"
width : "400",
height: "400"
});
let handleMessage = function (event) {
let origin = event.origin;
if( origin == "https://login.dingtalk.com" ) {
let loginTmpCode = event.data;
window.location.href="https://oapi.dingtalk.com/connect/oauth2/sns_authorize?appid=dingoap7dwt39svqfxlnkx&response_type=code&scope=snsapi_login&state=STATE&redirect_uri="+url+"&loginTmpCode="+loginTmpCode
var handleMessage = function (event) {
var origin = event.origin;
console.log("origin", event.origin);
//if( origin == "https://login.dingtalk.com" ) { //判断是否来自ddLogin扫码事件。
var loginTmpCode = event.data;
console.log("loginTmpCode", loginTmpCode);
// }
}
};
if (typeof window.addEventListener != 'undefined') {
window.addEventListener('message', handleMessage);
window.addEventListener('message', handleMessage, false);
} else if (typeof window.attachEvent != 'undefined') {
window.attachEvent('onmessage', handleMessage);
}
</script>
</body>
</html>
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment