Skip to content

Commit

Permalink
add files.
Browse files Browse the repository at this point in the history
  • Loading branch information
felix committed Dec 9, 2016
1 parent 2749d33 commit f48bd06
Show file tree
Hide file tree
Showing 2 changed files with 108 additions and 0 deletions.
40 changes: 40 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Logs
logs
*.log
npm-debug.log*

# Runtime data
pids
*.pid
*.seed

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage

# nyc test coverage
.nyc_output

# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# node-waf configuration
.lock-wscript

# Compiled binary addons (http://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules
jspm_packages

# Optional npm cache directory
.npm

# Optional REPL history
.node_repl_history

.idea
bower_components
68 changes: 68 additions & 0 deletions index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<?php
$appid = '';
$scope = 'snsapi_login';
$state = '';
$code = '';
$redirect_uri = '';

if (isset($_GET['device'])) {
$device = $_GET['device'];
}

if (isset($_GET['appid'])) {
$appid = $_GET['appid'];
}
if (isset($_GET['state'])) {
$state = $_GET['state'];
}
if (isset($_GET['redirect_uri'])) {
$redirect_uri = $_GET['redirect_uri'];
}
if (isset($_GET['code'])) {
$code = $_GET['code'];
}

if ($code == 'test') {
exit;
}

if (empty($code)) {
$authUrl = '';
if ($device == 'pc') {
$authUrl = 'https://open.weixin.qq.com/connect/qrconnect';
} else {
$authUrl = 'https://open.weixin.qq.com/connect/oauth2/authorize';
}

$options = [
$authUrl,
'?appid=' . $appid,
'&redirect_uri=' . urlencode($_SERVER['REQUEST_SCHEME'] . '://' . $_SERVER['HTTP_HOST'] . '/'),
'&response_type=code',
'&scope=' . $scope,
'&state=' . $state,
'#wechat_redirect'
];

//把redirect_uri先写到cookie
header(implode('', [
"Set-Cookie: redirect_uri=",
urlencode($redirect_uri),
"; path=/; domain=",
$_SERVER['HTTP_HOST'],
"; expires=" . gmstrftime("%A, %d-%b-%Y %H:%M:%S GMT", time() + 60),
"; Max-Age=" + 60,
"; httponly"
]));

header('Location: ' . implode('', $options));
} else {
if (isset($_COOKIE['redirect_uri'])) {
header('Location: ' . implode('', [
urldecode($_COOKIE['redirect_uri']),
'?code=' . $code,
'&state=' . $state
]));
}
}
?>

0 comments on commit f48bd06

Please sign in to comment.