Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
T
tl_estate
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
hujun
tl_estate
Commits
4a6d76ce
Commit
4a6d76ce
authored
Jun 05, 2018
by
clone
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
微信公众号
parent
529c98fb
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
187 additions
and
0 deletions
+187
-0
MP_verify_p9Ei8khm4IKSYIJa.txt
MP_verify_p9Ei8khm4IKSYIJa.txt
+2
-0
WxSdk.php
application/api/controller/WxSdk.php
+28
-0
WxCallbackUntils.php
application/api/untils/WxCallbackUntils.php
+105
-0
WxTest.php
application/index/controller/WxTest.php
+35
-0
test.html
application/index/view/wx_test/test.html
+11
-0
route.php
application/route.php
+6
-0
No files found.
MP_verify_p9Ei8khm4IKSYIJa.txt
0 → 100644
View file @
4a6d76ce
p9Ei8khm4IKSYIJa
\ No newline at end of file
application/api/controller/WxSdk.php
0 → 100644
View file @
4a6d76ce
<?php
namespace
app\api\controller
;
/**
* 微信jsSdk
* Created by zw.
* User: zw
* email 452436132@qq.com
* Date: 2018/06/04
* Time: 21:30
*/
use
app\api\extend\Basic
;
use
app\api\untils\WxCallbackUntils
;
class
WxSdk
extends
Basic
{
private
$wxCallbackApi
;
public
function
__construct
()
{
parent
::
__construct
();
$this
->
wxCallbackApi
=
new
WxCallbackUntils
();
}
}
application/api/untils/WxCallbackUntils.php
0 → 100644
View file @
4a6d76ce
<?php
namespace
app\api\untils
;
/**
* 微信接口api
* Created by zw.
* User: zw
* email 452436132@qq.com
* Date: 2018/06/04
* Time: 21:30
*/
class
WxCallbackUntils
{
private
$redis
;
private
$appId
;
private
$appSecret
;
public
function
__construct
()
{
$this
->
appId
=
"wxbbeb8cd2f4b72aea"
;
$this
->
appSecret
=
"9ac6d1680553f4b554f3b46d263fbfb3"
;
}
/**
* 跳授权页
* @param $redirect_url "http://www.zhuwei.site/index.php/Home/Index/getList";
*/
public
function
getWxCode
(
$redirect_url
)
{
$redirect_url
=
urlencode
(
$redirect_url
);
$url
=
"https://open.weixin.qq.com/connect/oauth2/authorize?appid="
.
$this
->
appId
.
"&redirect_uri="
.
$redirect_url
.
"&response_type=code&scope=snsapi_userinfo&state=STATE#wechat_redirect"
;
header
(
"Location:"
.
$url
);
}
/**
* 获取access_token
* @param $code
* @return mixed
*/
public
function
getAccessTokenByCode
(
$code
)
{
$oauth
=
'https://api.weixin.qq.com/sns/oauth2/access_token'
;
$params
[
'appid'
]
=
$this
->
appId
;
$params
[
'secret'
]
=
$this
->
appSecret
;
$params
[
'code'
]
=
$code
;
$params
[
'grant_type'
]
=
'authorization_code'
;
$result
=
$this
->
curl
(
$oauth
,
$params
);
return
$result
;
}
/**
* 获取用户信息
* @param $code
* @return array
*/
public
function
getUserInfoByAccessToken
(
$code
)
{
$access_token_info
=
$this
->
getAccessTokenByCode
(
$code
);
$access_token_info
=
json_decode
(
$access_token_info
);
$access_token
=
$access_token_info
->
access_token
;
$open_id
=
$access_token_info
->
openid
;
session
(
"access_token"
,
$access_token
);
session
(
"openid"
,
$open_id
);
$user_info_url
=
'https://api.weixin.qq.com/sns/userinfo'
;
$params
[
'access_token'
]
=
$access_token
;
$params
[
'openid'
]
=
$open_id
;
$params
[
'lang'
]
=
'zh_CN'
;
$user_info
=
$this
->
curl
(
$user_info_url
,
$params
);
$user_info
=
json_decode
(
$user_info
);
$data
=
array
(
'wx_open_id'
=>
$open_id
,
'buyer_nick'
=>
$user_info
->
nickname
,
'sex'
=>
$user_info
->
sex
,
'province'
=>
$user_info
->
province
,
'city'
=>
$user_info
->
city
,
'buyer_img'
=>
$user_info
->
headimgurl
);
session
(
"userInfo"
,
$data
);
return
$data
;
}
public
function
curl
(
$url
,
$data
=
[])
{
$ch
=
curl_init
();
curl_setopt
(
$ch
,
CURLOPT_HTTPHEADER
,
[]);
curl_setopt
(
$ch
,
CURLOPT_TIMEOUT
,
5
);
curl_setopt
(
$ch
,
CURLOPT_SSL_VERIFYPEER
,
0
);
curl_setopt
(
$ch
,
CURLOPT_COOKIEJAR
,
null
);
curl_setopt
(
$ch
,
CURLOPT_RETURNTRANSFER
,
1
);
curl_setopt
(
$ch
,
CURLOPT_URL
,
$url
);
curl_setopt
(
$ch
,
CURLOPT_POST
,
true
);
curl_setopt
(
$ch
,
CURLOPT_POSTFIELDS
,
$data
);
$content
=
curl_exec
(
$ch
);
return
$content
;
}
}
application/index/controller/WxTest.php
0 → 100644
View file @
4a6d76ce
<?php
namespace
app\index\controller
;
use
app\api\untils\WxCallbackUntils
;
/**
* Created by PhpStorm.
* User : zw
* Date : 2018/6/4
* Time : 18:06
* Intro:
*/
class
WxTest
{
private
$url
=
"https://pre2.tonglianjituan.com/index/test"
;
private
$_wxApi
;
public
function
__construct
()
{
$this
->
_wxApi
=
new
WxCallbackUntils
();
}
public
function
test
()
{
$userInfo
=
session
(
"userInfo"
);
dump
(
$userInfo
);
if
(
!
$userInfo
)
{
$this
->
_wxApi
->
getWxCode
(
$this
->
url
);
}
else
{
return
view
(
"test"
);
}
}
}
\ No newline at end of file
application/index/view/wx_test/test.html
0 → 100644
View file @
4a6d76ce
<!DOCTYPE html>
<html
lang=
"en"
>
<head>
<meta
charset=
"UTF-8"
>
<title>
11
</title>
</head>
<body>
123123123
</body>
</html>
\ No newline at end of file
application/route.php
View file @
4a6d76ce
...
@@ -235,6 +235,12 @@ Route::group('index', [
...
@@ -235,6 +235,12 @@ Route::group('index', [
'getTaxesById'
=>
[
'index/Finance/getTaxesById'
,
[
'method'
=>
'POST|GET'
]
],
//财务结单
'getTaxesById'
=>
[
'index/Finance/getTaxesById'
,
[
'method'
=>
'POST|GET'
]
],
//财务结单
'test'
=>
[
'index/WxTest/test'
,
[
'method'
=>
'POST|GET'
]
],
//wx
]);
]);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment