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
af75f958
Commit
af75f958
authored
Jun 07, 2018
by
clone
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
微信绑定
parent
e67e7d01
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
145 additions
and
17 deletions
+145
-17
WxSdk.php
application/api/controller/WxSdk.php
+59
-7
WxSdkService.php
application/api/service/WxSdkService.php
+13
-0
UWxInfoValidate.php
application/api/validate/UWxInfoValidate.php
+7
-1
UWxInfo.php
application/model/UWxInfo.php
+65
-9
route.php
application/route.php
+1
-0
No files found.
application/api/controller/WxSdk.php
View file @
af75f958
...
...
@@ -25,12 +25,16 @@ class WxSdk extends Basic
$this
->
wxInfoModel
=
new
UWxInfo
();
}
/**
* wx授权拉取数据
* @return \think\Response
*/
public
function
saveWxInfo
()
{
$params
=
$this
->
params
;
/* $params = array(
/* $params = array(
"wx_open_id" => "123132123123123",
"buyer_nick" => "123123123
",
"buyer_nick" => "222222222
",
"buyer_img" => "123123123",
"sex" => 1,
"province" => "123123123",
...
...
@@ -42,15 +46,63 @@ class WxSdk extends Basic
return
$this
->
response
(
"101"
,
$checkResult
);
}
try
{
$wx_open_id
=
$params
[
"wx_open_id"
];
// 验证open_id是否已经存在,存在则更新
$wxInfoObj
=
$this
->
wxInfoModel
->
getWxInfoByOpenId
(
$wx_open_id
);
try
{
if
(
$wxInfoObj
&&
count
(
$wxInfoObj
)
>
0
)
{
$params
[
"id"
]
=
$wxInfoObj
[
0
][
"id"
];
$id
=
$this
->
wxInfoModel
->
updateWxInfo
(
$params
);
}
else
{
$id
=
$this
->
wxInfoModel
->
addWxInfo
(
$params
);
if
(
$id
>
0
){
return
$this
->
response
(
"200"
,
"request success"
,[
"id"
=>
$id
]);
}
}
catch
(
Exception
$exception
){
return
$this
->
response
(
"101"
,
"request error:"
.
$exception
);
}
catch
(
Exception
$exception
)
{
return
$this
->
response
(
"101"
,
"request error:"
.
$exception
);
}
if
(
$id
>
0
)
{
return
$this
->
response
(
"200"
,
"request success"
,
[
"id"
=>
$id
]);
}
else
{
return
$this
->
response
(
"101"
,
"request exception"
);
}
}
/**
* 绑定用户 记录最后一次绑定
* @return \think\Response
*/
public
function
bindUserId
()
{
$params
=
$this
->
params
;
/* $params = array(
"wx_open_id" => "123132123123123",
"user_id" => 2
);*/
$checkResult
=
$this
->
validate
(
$params
,
"UWxInfoValidate.bind"
);
if
(
true
!==
$checkResult
)
{
return
$this
->
response
(
"101"
,
$checkResult
);
}
$wx_open_id
=
$params
[
"wx_open_id"
];
// 验证open_id是否已经存在,存在则更新
$wxInfoObj
=
$this
->
wxInfoModel
->
getWxInfoByOpenId
(
$wx_open_id
);
if
(
$wxInfoObj
&&
count
(
$wxInfoObj
)
>
0
)
{
$params
[
"id"
]
=
$wxInfoObj
[
0
][
"id"
];
try
{
$id
=
$this
->
wxInfoModel
->
updateWxInfo
(
$params
);
if
(
$id
>
0
)
{
return
$this
->
response
(
"200"
,
"request success"
,
[
"id"
=>
$id
]);
}
else
{
return
$this
->
response
(
"101"
,
"绑定失败"
);
}
}
catch
(
Exception
$exception
)
{
return
$this
->
response
(
"101"
,
"request error:"
.
$exception
);
}
}
else
{
return
$this
->
response
(
"101"
,
"没有找到用户对应微信记录"
);
}
}
...
...
application/api/service/WxSdkService.php
0 → 100644
View file @
af75f958
<?php
namespace
app\api\service
;
/**
* Created by PhpStorm.
* User : zw
* Date : 2018/6/7
* Time : 14:06
* Intro:
*/
class
WxSdkService
{
}
\ No newline at end of file
application/api/validate/UWxInfoValidate.php
View file @
af75f958
...
...
@@ -17,6 +17,7 @@ class UWxInfoValidate extends Validate
'wx_open_id'
=>
'require|length:10,50'
,
'sex'
=>
'require|number'
,
'source'
=>
'require|number'
,
'user_id'
=>
'require|number|gt:0'
,
];
protected
$message
=
[
...
...
@@ -26,10 +27,14 @@ class UWxInfoValidate extends Validate
'sex.number'
=>
'性别必须是数字'
,
'source.require'
=>
'来源为必须字段'
,
'source.number'
=>
'来源必须是数字'
,
'user_id.require'
=>
'user_id为必须字段'
,
'user_id.number'
=>
'user_id必须是数字'
,
'user_id.gt'
=>
'user_id必须大于0'
,
];
protected
$scene
=
[
'add'
=>
[
'wx_open_id'
,
'sex'
,
'source'
],
'add'
=>
[
'wx_open_id'
,
'sex'
,
'source'
],
'select'
=>
[
'wx_open_id'
],
'bind'
=>
[
'wx_open_id'
,
'user_id'
],
];
}
\ No newline at end of file
application/model/UWxInfo.php
View file @
af75f958
...
...
@@ -18,45 +18,101 @@ class UWxInfo extends Model
// 设置当前模型对应的完整数据表名称
protected
$table
=
'u_wx_info'
;
public
function
__construct
()
{
}
/**
* 新增微信拉取用户信息
* @param $params
* @return int|string
* @throws Exception
*/
public
function
addWxInfo
(
$params
)
public
function
addWxInfo
(
array
$params
)
:
int
{
$wxBin
=
$this
->
wxInfoBin
(
$params
);
Db
::
startTrans
();
try
{
try
{
$id
=
$this
->
insertGetId
(
$wxBin
);
Db
::
commit
();
return
$id
;
}
catch
(
Exception
$exception
){
}
catch
(
Exception
$exception
)
{
Db
::
rollback
();
throw
$exception
;
}
}
/**
* 修改微信拉取用户信息
* @param array $params
* @return int
* @throws Exception
*/
public
function
updateWxInfo
(
array
$params
)
:
int
{
$wxBin
=
$this
->
wxInfoBin
(
$params
);
Db
::
startTrans
();
try
{
$this
->
where
([
"id"
=>
$wxBin
[
"id"
]
])
->
update
(
$wxBin
);
Db
::
commit
();
return
$params
[
"id"
];
}
catch
(
Exception
$exception
)
{
Db
::
rollback
();
throw
$exception
;
}
}
/**
* 根据微信open_id获取id
* @param string $open_id
* @return false|\PDOStatement|string|\think\Collection
*/
public
function
getWxInfoByOpenId
(
string
$open_id
)
{
$where_
[
"wx_open_id"
]
=
$open_id
;
$where_
[
"is_del"
]
=
0
;
return
$this
->
field
(
"id"
)
->
where
(
$where_
)
->
select
();
}
/**
* bin
* @param $params
* @return array
*/
private
function
wxInfoBin
(
$params
)
{
$arr
=
[];
if
(
isset
(
$params
[
"id"
]))
{
$arr
[
"wx_open_id"
]
=
$params
[
"id"
];
$arr
[
"id"
]
=
$params
[
"id"
];
}
else
{
$arr
[
"create_time"
]
=
date
(
"Y-m-d H:i:s"
,
time
());
}
if
(
isset
(
$params
[
"user_id"
]))
{
$arr
[
"user_id"
]
=
$params
[
"user_id"
];
}
if
(
isset
(
$params
[
"wx_open_id"
]))
{
$arr
[
"wx_open_id"
]
=
$params
[
"wx_open_id"
];
}
if
(
isset
(
$params
[
"buyer_nick"
]))
{
$arr
[
"buyer_nick"
]
=
$params
[
"buyer_nick"
];
}
if
(
isset
(
$params
[
"buyer_img"
]))
{
$arr
[
"buyer_img"
]
=
$params
[
"buyer_img"
];
}
if
(
isset
(
$params
[
"sex"
]))
{
$arr
[
"sex"
]
=
$params
[
"sex"
];
}
if
(
isset
(
$params
[
"province"
]))
{
$arr
[
"province"
]
=
$params
[
"province"
];
}
if
(
isset
(
$params
[
"city"
]))
{
$arr
[
"city"
]
=
$params
[
"city"
];
}
if
(
isset
(
$params
[
"source"
]))
{
$arr
[
"source"
]
=
$params
[
"source"
];
$arr
[
"create_time"
]
=
date
(
"Y-m-d H:i:s"
,
time
());
}
$arr
[
"update_time"
]
=
date
(
"Y-m-d H:i:s"
,
time
());
return
$arr
;
}
...
...
application/route.php
View file @
af75f958
...
...
@@ -320,6 +320,7 @@ Route::group('api', [
'saveWxInfo'
=>
[
'api/WxSdk/saveWxInfo'
,
[
'method'
=>
'POST|GET'
]
],
//wx
'bindUserId'
=>
[
'api/WxSdk/bindUserId'
,
[
'method'
=>
'POST|GET'
]
],
//wx
]);
Route
::
group
(
'chat'
,
[
...
...
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