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
3df47e9d
Commit
3df47e9d
authored
Aug 29, 2019
by
zhuwei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
小程序获取oppenid等
parent
95e0ef04
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
125 additions
and
4 deletions
+125
-4
WxSdk.php
application/api/controller/WxSdk.php
+70
-1
Basic.php
application/api/extend/Basic.php
+3
-0
WxSdkService.php
application/api/service/WxSdkService.php
+41
-0
UWxInfoValidate.php
application/api/validate/UWxInfoValidate.php
+8
-3
route.php
application/route.php
+3
-0
No files found.
application/api/controller/WxSdk.php
View file @
3df47e9d
...
@@ -13,6 +13,7 @@ namespace app\api\controller;
...
@@ -13,6 +13,7 @@ namespace app\api\controller;
use
app\api\extend\Basic
;
use
app\api\extend\Basic
;
use
app\api\service\RegisterService
;
use
app\api\service\RegisterService
;
use
app\api\service\WxSdkService
;
use
app\api\untils\JwtUntils
;
use
app\api\untils\JwtUntils
;
use
app\model\Users
;
use
app\model\Users
;
use
app\model\UWxInfo
;
use
app\model\UWxInfo
;
...
@@ -147,7 +148,75 @@ class WxSdk extends Basic
...
@@ -147,7 +148,75 @@ class WxSdk extends Basic
return
$this
->
response
(
"101"
,
"request error:"
.
$exception
);
return
$this
->
response
(
"101"
,
"request error:"
.
$exception
);
}
}
}
else
{
}
else
{
return
$this
->
response
(
"101"
,
"没有找到用户对应微信记录"
);
}
}
/**
* 获取小程序openid、unionid等数据
* @return \think\Response
*/
public
function
getOpenidByCode
()
{
$params
=
$this
->
params
;
/* $params = array(
"code" => "123132123123123",
);*/
$checkResult
=
$this
->
validate
(
$params
,
"UWxInfoValidate.getOpenidByCode"
);
if
(
true
!==
$checkResult
)
{
return
$this
->
response
(
"101"
,
$checkResult
);
}
$s_wx
=
new
WxSdkService
();
$res
=
$s_wx
->
getOpenidByCode
(
$params
[
'code'
]);
if
(
$res
[
'errcode'
]
==
0
){
return
$this
->
response
(
"200"
,
"request success"
,
$res
);
}
else
{
return
$this
->
response
(
"101"
,
$res
[
'errmsg'
]);
}
}
/**
* 保存微信登录信息
* @return \think\Response
*/
public
function
saveWXInfoByPortableProgram
()
{
$params
=
$this
->
params
;
/* $params = array(
"wx_open_id" => "123132123123123",
"wx_union_id" => "123132123123123",
"buyer_nick" => "222222222",
"buyer_img" => "123123123",
"sex" => 1,
"province" => "123123123",
"city" => "123123123",
"source" => 1,// 0:h5邀请 1安卓 2苹果',
);*/
$checkResult
=
$this
->
validate
(
$params
,
"UWxInfoValidate.add"
);
if
(
true
!==
$checkResult
)
{
return
$this
->
response
(
"101"
,
$checkResult
);
}
$wx_union_id
=
$params
[
"wx_union_id"
];
// 验证open_id是否已经存在,存在则更新
$wxInfoObj
=
$this
->
wxInfoModel
->
getWxInfoByOpenId
(
$wx_union_id
);
try
{
if
(
$wxInfoObj
&&
count
(
$wxInfoObj
)
>
0
)
{
$params
[
"id"
]
=
$wxInfoObj
[
0
][
"id"
];
$id
=
$this
->
wxInfoModel
->
updateWxInfo
(
$params
);
}
else
{
$id
=
$this
->
wxInfoModel
->
addWxInfo
(
$params
);
}
}
catch
(
Exception
$exception
)
{
return
$this
->
response
(
"101"
,
"request error:"
.
$exception
);
}
if
(
$id
>
0
)
{
return
$this
->
response
(
"200"
,
"request success"
);
}
else
{
return
$this
->
response
(
"101"
,
"request exception"
);
}
}
}
}
...
...
application/api/extend/Basic.php
View file @
3df47e9d
...
@@ -78,6 +78,9 @@ class Basic extends Controller
...
@@ -78,6 +78,9 @@ class Basic extends Controller
"office_api/getBuildingRoomList"
,
"office_api/getBuildingRoomList"
,
"office_api/filtrateConditionRoom"
,
"office_api/filtrateConditionRoom"
,
"office_api/getOfficeBuildingInfoShare"
,
"office_api/getOfficeBuildingInfoShare"
,
"api/getOpenidByCode"
,
"api/saveWXInfoByPortableProgram"
,
);
);
/**
/**
...
...
application/api/service/WxSdkService.php
View file @
3df47e9d
<?php
<?php
namespace
app\api\service
;
namespace
app\api\service
;
use
app\chat\utils\CurlUtil
;
/**
/**
* Created by PhpStorm.
* Created by PhpStorm.
* User : zw
* User : zw
...
@@ -8,5 +10,43 @@ namespace app\api\service;
...
@@ -8,5 +10,43 @@ namespace app\api\service;
* Intro:
* Intro:
*/
*/
class
WxSdkService
{
class
WxSdkService
{
private
$appId
;
private
$appSecret
;
public
function
__construct
()
{
// $this->appId = "wxbbeb8cd2f4b72aea";
// $this->appSecret = "9ac6d1680553f4b554f3b46d263fbfb3";
if
(
strpos
(
$this
->
http_host
(),
'api'
)
!==
false
)
{
$this
->
appId
=
"wxbbeb8cd2f4b72aea"
;
$this
->
appSecret
=
"9ac6d1680553f4b554f3b46d263fbfb3"
;
}
else
{
$this
->
appId
=
"wxd30d74d1126d3278"
;
//测试
$this
->
appSecret
=
"f29c8c502549020d2193a464be9632dc"
;
//测试
}
}
/**
* 获取小程序openid、unionid等数据
* @param $code
* @return \app\chat\utils\CurlResponse|mixed
*/
public
function
getOpenidByCode
(
$code
)
{
$curl
=
new
CurlUtil
();
$url
=
"https://api.weixin.qq.com/sns/jscode2session?appid=
{
$this
->
appId
}
&secret=
{
$this
->
appSecret
}
&js_code=
{
$code
}
&grant_type=authorization_code"
;
$result
=
$curl
->
get
(
$url
);
$result
=
json_decode
(
$result
,
"true"
);
return
$result
;
}
public
function
http_host
()
{
$http_type
=
((
isset
(
$_SERVER
[
'HTTPS'
])
&&
$_SERVER
[
'HTTPS'
]
==
'on'
)
||
(
isset
(
$_SERVER
[
'HTTP_X_FORWARDED_PROTO'
])
&&
$_SERVER
[
'HTTP_X_FORWARDED_PROTO'
]
==
'https'
))
?
'https://'
:
'http://'
;
$host
=
$http_type
.
$_SERVER
[
'HTTP_HOST'
];
return
$host
;
}
}
}
\ No newline at end of file
application/api/validate/UWxInfoValidate.php
View file @
3df47e9d
...
@@ -19,6 +19,8 @@ class UWxInfoValidate extends Validate
...
@@ -19,6 +19,8 @@ class UWxInfoValidate extends Validate
'sex'
=>
'require|number'
,
'sex'
=>
'require|number'
,
'source'
=>
'require|number'
,
'source'
=>
'require|number'
,
'user_id'
=>
'require|number|gt:0'
,
'user_id'
=>
'require|number|gt:0'
,
'code'
=>
'require'
,
];
];
protected
$message
=
[
protected
$message
=
[
...
@@ -33,11 +35,13 @@ class UWxInfoValidate extends Validate
...
@@ -33,11 +35,13 @@ class UWxInfoValidate extends Validate
'user_id.require'
=>
'user_id为必须字段'
,
'user_id.require'
=>
'user_id为必须字段'
,
'user_id.number'
=>
'user_id必须是数字'
,
'user_id.number'
=>
'user_id必须是数字'
,
'user_id.gt'
=>
'user_id必须大于0'
,
'user_id.gt'
=>
'user_id必须大于0'
,
'code.require'
=>
'code不能为空'
,
];
];
protected
$scene
=
[
protected
$scene
=
[
'add'
=>
[
'wx_open_id'
,
'wx_union_id'
,
'sex'
,
'source'
],
'add'
=>
[
'wx_open_id'
,
'wx_union_id'
,
'sex'
,
'source'
],
'select'
=>
[
'wx_open_id'
],
'select'
=>
[
'wx_open_id'
],
'bind'
=>
[
'wx_open_id'
,
'user_id'
],
'bind'
=>
[
'wx_open_id'
,
'user_id'
],
'getOpenidByCode'
=>
[
'code'
],
];
];
}
}
\ No newline at end of file
application/route.php
View file @
3df47e9d
...
@@ -655,6 +655,9 @@ Route::group('api', [
...
@@ -655,6 +655,9 @@ Route::group('api', [
'saveWxInfo'
=>
[
'api/WxSdk/saveWxInfo'
,
[
'method'
=>
'POST'
]],
//wx
'saveWxInfo'
=>
[
'api/WxSdk/saveWxInfo'
,
[
'method'
=>
'POST'
]],
//wx
'bindUserId'
=>
[
'api/WxSdk/bindUserId'
,
[
'method'
=>
'POST|GET'
]],
//wx
'bindUserId'
=>
[
'api/WxSdk/bindUserId'
,
[
'method'
=>
'POST|GET'
]],
//wx
'getOpenidByCode'
=>
[
'api/WxSdk/getOpenidByCode'
,
[
'method'
=>
'POST'
]],
//wx
'saveWXInfoByPortableProgram'
=>
[
'api/WxSdk/saveWXInfoByPortableProgram'
,
[
'method'
=>
'POST'
]],
'sendCode'
=>
[
'api/Register/registerSendCode'
,
[
'method'
=>
'POST'
]],
'sendCode'
=>
[
'api/Register/registerSendCode'
,
[
'method'
=>
'POST'
]],
'userVerify'
=>
[
'api/Register/registerVerify'
,
[
'method'
=>
'POST'
]],
'userVerify'
=>
[
'api/Register/registerVerify'
,
[
'method'
=>
'POST'
]],
...
...
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