Commit d0a0587a authored by zhoujun's avatar zhoujun

调试钉钉

parent b682c964
...@@ -31,10 +31,11 @@ class UserController extends BaseController ...@@ -31,10 +31,11 @@ class UserController extends BaseController
*/ */
public function getLogin(Request $request) public function getLogin(Request $request)
{ {
$key = env('dingoap7dwt39svqfxlnkx'); return view('login.index', []);
$redirectUri = env('dingoap7dwt39svqfxlnkx'); //$key = env('DD_APP_KEY');
$url = 'https://oapi.dingtalk.com/connect/qrconnect?appid='.$key.'&response_type=code&scope=snsapi_login&state=STATE&redirect_uri='.$redirectUri; //$redirectUri = env('REDIRECT_URL');
return 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 ...@@ -46,71 +47,25 @@ class UserController extends BaseController
public function getReturnLogin(Request $request) public function getReturnLogin(Request $request)
{ {
$Input = $request->all(); $Input = $request->all();
$accessKey = env('DD_APP_SECRET'); print_r($Input);
$timestamp = $this->getmTime(); // include "TopSdk.php";
$signature = $this->getsignature($timestamp,$accessKey); // $c = new DingTalkClient(DingTalkConstant::$CALL_TYPE_OAPI, DingTalkConstant::$METHOD_POST , DingTalkConstant::$FORMAT_JSON);
$url = 'https://oapi.dingtalk.com/sns/getuserinfo_bycode?accessKey=' . $accessKey . '&timestamp=' . $timestamp . '&signature=' . $signature; // $req = new OapiSnsGetuserinfoBycodeRequest;
$data = [ 'tmp_auth_code' => $Input['code'] ]; // $req->setTmpAuthCode("4a2c5695b78738d495f47b5fee9160cd");
$userInfo = $this->curl_json($url, $data); // $resp=$c->executeWithAccessKey($req, "https://oapi.dingtalk.com/sns/getuserinfo_bycode","yourAppId","yourAppSecret");
$res = json_decode($userInfo, true); // var_dump($resp);
print_r($res);die();
if(isset($res['errcode']) and $res['errcode'] == 0) {
}
}
/**
* 计算签名
* @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;
} }
/** public function test(){
* 毫秒级时间戳 include "TopSdk.php";
* @return float $c = new DingTalkClient(DingTalkConstant::$CALL_TYPE_OAPI, DingTalkConstant::$METHOD_POST , DingTalkConstant::$FORMAT_JSON);
*/ $req = new OapiSnsGetuserinfoBycodeRequest;
public function getmTime() $req->setTmpAuthCode("4a2c5695b78738d495f47b5fee9160cd");
{ $resp=$c->executeWithAccessKey($req, "https://oapi.dingtalk.com/sns/getuserinfo_bycode","yourAppId","yourAppSecret");
list($s1, $s2) = explode(' ', microtime()); var_dump($resp);
$mTime = (float)sprintf('%.0f', (floatval($s1) + floatval($s2)) * 1000);
return $mTime;
} }
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 * @return array
......
<!doctype html>
<html lang="en"> <html lang="en">
<head> <head>
<meta charset="UTF-8"> <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" /> <meta name="viewport"
<title>apk管理</title> content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<link rel="icon" type="image/png" sizes="192x192" href=""> <meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>apk文件包上传</title>
<style type="text/css"> <style>
ul {
width: 300px;
}
img {
display: block;
width: 100%;
height: 300px;
margin-bottom: 20px;
}
#login_container{
margin: 200px auto;
width: 400px;
}
</style> </style>
<script src="https://g.alicdn.com/dingding/dinglogin/0.0.5/ddLogin.js"></script>
</head> </head>
<body> <body>
<div id="login_container" style="width: 400px; margin:200px auto;"></div> <div id="login_container"></div>
<script src="https://g.alicdn.com/dingding/dinglogin/0.0.5/ddLogin.js"></script>
<script> <script>
var url = encodeURIComponent('http://upload-apk.srccwl.com/return/login'); let 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 goto = encodeURIComponent('https://oapi.dingtalk.com/connect/oauth2/sns_authorize?appid=dingoap7dwt39svqfxlnkx&response_type=code&scope=snsapi_login&state=STATE&redirect_uri='+url)
DDLogin({ DDLogin({
id:"login_container", id:"login_container",
goto: goto, goto: goto,
style: "border:none;background-color:#FFFFFF;", width : "400",
width : "322", height: "400"
height: "320"
}); });
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 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') { if (typeof window.addEventListener != 'undefined') {
window.addEventListener('message', handleMessage); window.addEventListener('message', handleMessage, false);
} else if (typeof window.attachEvent != 'undefined') { } else if (typeof window.attachEvent != 'undefined') {
window.attachEvent('onmessage', handleMessage); window.attachEvent('onmessage', handleMessage);
} }
</script> </script>
</body> </body>
</html> </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