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
056356b8
Commit
056356b8
authored
Jun 13, 2018
by
clone
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
微信数据保存
parent
976b15b4
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
120 additions
and
70 deletions
+120
-70
Register.php
application/api/controller/Register.php
+16
-6
WxSdk.php
application/api/controller/WxSdk.php
+3
-2
MessageUntils.php
application/api/untils/MessageUntils.php
+70
-44
WxCallbackUntils.php
application/api/untils/WxCallbackUntils.php
+2
-1
RegisterValidate.php
application/api/validate/RegisterValidate.php
+5
-1
UWxInfoValidate.php
application/api/validate/UWxInfoValidate.php
+17
-14
WxTest.php
application/index/controller/WxTest.php
+2
-0
UWxInfo.php
application/model/UWxInfo.php
+5
-2
No files found.
application/api/controller/Register.php
View file @
056356b8
...
...
@@ -4,6 +4,7 @@ namespace app\api\controller;
use
app\api\extend\Basic
;
use
app\api\untils\MessageUntils
;
use
app\extra\RedisExt
;
use
think\Request
;
/**
...
...
@@ -15,9 +16,12 @@ use think\Request;
*/
class
Register
extends
Basic
{
private
$messageUntil
;
function
__construct
(
$request
=
null
)
{
parent
::
__construct
(
$request
);
$this
->
messageUntil
=
new
MessageUntils
();
}
/**
...
...
@@ -35,8 +39,7 @@ class Register extends Basic
if
(
true
!==
$checkResult
)
{
return
$this
->
response
(
"101"
,
$checkResult
);
}
$message
=
new
MessageUntils
();
$result
=
$message
->
sendCheckCodeV2
(
$params
[
'device_id'
],
$params
[
'phone'
]);
$result
=
$this
->
messageUntil
->
sendCheckCodeV2
(
$params
[
'device_id'
],
$params
[
'phone'
]);
if
(
$result
==
'true'
)
{
return
$this
->
response
(
"200"
,
"request success"
,
$result
);
}
else
{
...
...
@@ -49,15 +52,21 @@ class Register extends Basic
{
$params
=
$this
->
params
;
$params
=
array
(
"phone"
=>
"16617616471"
,
"device_id"
=>
"1111"
,
"code"
=>
1231
,
"
union_id"
=>
"phone"
=>
"16617616471"
,
"device_id"
=>
"1111"
,
"code"
=>
1231
,
"
wx_open_id"
=>
"1111111111"
//false
);
$checkResult
=
$this
->
validate
(
$params
,
"RegisterValidate.register"
);
if
(
true
!==
$checkResult
)
{
return
$this
->
response
(
"101"
,
$checkResult
);
}
$is_eq
=
$this
->
messageUntil
->
verifyCode
(
$params
[
"device_id"
],
$params
[
"code"
]);
if
(
!
$is_eq
)
{
return
$this
->
response
(
"101"
,
"验证码错误"
);
}
}
}
\ No newline at end of file
application/api/controller/WxSdk.php
View file @
056356b8
...
...
@@ -34,6 +34,7 @@ class WxSdk extends Basic
$params
=
$this
->
params
;
/* $params = array(
"wx_open_id" => "123132123123123",
"wx_union_id" => "123132123123123",
"buyer_nick" => "222222222",
"buyer_img" => "123123123",
"sex" => 1,
...
...
@@ -46,10 +47,10 @@ class WxSdk extends Basic
return
$this
->
response
(
"101"
,
$checkResult
);
}
$wx_
open_id
=
$params
[
"wx_ope
n_id"
];
$wx_
union_id
=
$params
[
"wx_unio
n_id"
];
// 验证open_id是否已经存在,存在则更新
$wxInfoObj
=
$this
->
wxInfoModel
->
getWxInfoByOpenId
(
$wx_
ope
n_id
);
$wxInfoObj
=
$this
->
wxInfoModel
->
getWxInfoByOpenId
(
$wx_
unio
n_id
);
try
{
if
(
$wxInfoObj
&&
count
(
$wxInfoObj
)
>
0
)
{
$params
[
"id"
]
=
$wxInfoObj
[
0
][
"id"
];
...
...
application/api/untils/MessageUntils.php
View file @
056356b8
...
...
@@ -4,7 +4,7 @@
* User : hj
* Date : 2017.12.6
* Time : 16:14
* Intro:
* Intro:
*/
namespace
app\api\untils
;
...
...
@@ -12,12 +12,14 @@ namespace app\api\untils;
use
app\extra\RedisExt
;
use
app\model\NoteLog
;
class
MessageUntils
{
public
function
__construct
()
{
class
MessageUntils
{
public
function
__construct
()
{
}
/**
* 短信验证码
* 容云通讯
...
...
@@ -27,7 +29,8 @@ class MessageUntils {
* @param string $tempId
* @return SimpleXMLElement[]
*/
public
function
sendCCPSMS
(
$to
,
$datas
,
$tempId
=
'214759'
)
{
public
function
sendCCPSMS
(
$to
,
$datas
,
$tempId
=
'214759'
)
{
import
(
'CCPRestSDK'
,
EXTEND_PATH
,
'.php'
);
$accountSid
=
'8a48b55153eae51101540e763d3b3888'
;
$accountToken
=
'26b220de299d4a56a6f54dd5792a30e4'
;
...
...
@@ -48,18 +51,18 @@ class MessageUntils {
$result
[
'dateCreated'
]
=
''
;
$result
[
'smsMessageSid'
]
=
''
;
$result
[
'statusMsg'
]
=
''
;
$result
=
(
array
)
$rest
->
sendTemplateSMS
(
$to
,
$datas
,
$tempId
);
if
(
$result
==
NULL
)
{
$result
=
(
array
)
$rest
->
sendTemplateSMS
(
$to
,
$datas
,
$tempId
);
if
(
$result
==
NULL
)
{
$data
[
'statusMsg'
]
=
'短信接口无返回'
;
$data
[
'statusCode'
]
=
-
1
;
}
if
(
$result
[
'statusCode'
]
!=
0
)
{
if
(
$result
[
'statusCode'
]
!=
0
)
{
$data
[
'statusCode'
]
=
$result
[
'statusCode'
];
$data
[
'statusMsg'
]
=
$result
[
'statusMsg'
];
}
else
{
$data
[
'statusCode'
]
=
$result
[
'statusCode'
];
$data
[
'TemplateSMS'
]
=
$result
[
'TemplateSMS'
];
}
else
{
$data
[
'statusCode'
]
=
$result
[
'statusCode'
];
$data
[
'TemplateSMS'
]
=
$result
[
'TemplateSMS'
];
}
return
$data
;
...
...
@@ -74,24 +77,25 @@ class MessageUntils {
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public
function
sendCheckCode
(
$phone
)
{
public
function
sendCheckCode
(
$phone
)
{
$result_data
[
'msg'
]
=
''
;
$result_data
[
'status'
]
=
true
;
$noteLog
=
new
NoteLog
();
$send_time
=
$noteLog
->
field
(
'send_time'
)
->
where
(
'phone'
,
$phone
)
->
where
(
'is_success'
,
1
)
->
where
(
'send_time'
,
'between time'
,[
date
(
'Y-m-d'
)
.
' 00:00:00'
,
date
(
'Y-m-d'
)
.
' 23:59:59'
])
$noteLog
=
new
NoteLog
();
$send_time
=
$noteLog
->
field
(
'send_time'
)
->
where
(
'phone'
,
$phone
)
->
where
(
'is_success'
,
1
)
->
where
(
'send_time'
,
'between time'
,
[
date
(
'Y-m-d'
)
.
' 00:00:00'
,
date
(
'Y-m-d'
)
.
' 23:59:59'
])
->
select
();
$num
=
count
(
$send_time
);
//发送数量
$num
=
count
(
$send_time
);
//发送数量
if
(
!
empty
(
$send_time
[
$num
-
1
])
&&
(
time
()
-
strtotime
(
$send_time
[
$num
-
1
]
->
send_time
)
<
58
)
&&
$num
!=
0
)
{
if
(
!
empty
(
$send_time
[
$num
-
1
])
&&
(
time
()
-
strtotime
(
$send_time
[
$num
-
1
]
->
send_time
)
<
58
)
&&
$num
!=
0
)
{
$result_data
[
'msg'
]
=
'1分钟内不能再次获取验证码'
;
$result_data
[
'status'
]
=
false
;
return
$result_data
;
}
if
(
$num
>
7
){
if
(
$num
>
7
)
{
$result_data
[
'msg'
]
=
'短信发送超过上限'
;
$result_data
[
'status'
]
=
false
;
return
$result_data
;
...
...
@@ -99,25 +103,25 @@ class MessageUntils {
$message
=
new
MessageUntils
();
$_code
=
mt_rand
(
1000
,
9999
)
.
''
;
$result
=
$message
->
sendCCPSMS
(
$phone
,
array
(
$_code
,
'5分钟'
),
214759
);
$result
=
$message
->
sendCCPSMS
(
$phone
,
array
(
$_code
,
'5分钟'
),
214759
);
$noteLog
->
phone
=
$phone
;
$noteLog
->
template_msg
=
'【同联商业】您的验证码为'
.
$_code
.
',请于5分钟内正确输入,如非本人操作,请忽略此短信。'
;
$noteLog
->
template_msg
=
'【同联商业】您的验证码为'
.
$_code
.
',请于5分钟内正确输入,如非本人操作,请忽略此短信。'
;
$noteLog
->
code
=
$_code
;
$noteLog
->
send_time
=
date
(
'Y-m-d H:i:s'
);
$result
[
'statusCode'
]
=
0
;
$result
[
'statusCode'
]
=
0
;
if
(
$result
[
'statusCode'
]
==
"000000"
)
{
$jwt
=
new
JwtUntils
();
$jwt
=
new
JwtUntils
();
$noteLog
->
is_success
=
1
;
$jwt_data
[
'phone'
]
=
$phone
;
$jwt_data
[
'code'
]
=
$_code
;
$result_data
[
'sms_code'
]
=
$_code
;
$result_data
[
'token'
]
=
$jwt
->
createToken
(
$jwt_data
);
$result_data
[
'status'
]
=
true
;
$result_data
[
'sms_code'
]
=
$_code
;
$result_data
[
'token'
]
=
$jwt
->
createToken
(
$jwt_data
);
$result_data
[
'status'
]
=
true
;
}
else
{
$noteLog
->
is_success
=
2
;
$noteLog
->
is_success
=
2
;
$result_data
[
'status'
]
=
false
;
}
$noteLog
->
save
();
...
...
@@ -129,41 +133,42 @@ class MessageUntils {
* @param $phone
* @return mixed
*/
public
function
sendCheckCodeV2
(
$device_id
,
$phone
)
{
$noteLog
=
new
NoteLog
();
$send_time
=
$noteLog
->
field
(
'send_time'
)
->
where
(
'phone'
,
$phone
)
->
where
(
'is_success'
,
1
)
->
where
(
'send_time'
,
'between time'
,[
date
(
'Y-m-d'
)
.
' 00:00:00'
,
date
(
'Y-m-d'
)
.
' 23:59:59'
])
public
function
sendCheckCodeV2
(
$device_id
,
$phone
)
{
$noteLog
=
new
NoteLog
();
$send_time
=
$noteLog
->
field
(
'send_time'
)
->
where
(
'phone'
,
$phone
)
->
where
(
'is_success'
,
1
)
->
where
(
'send_time'
,
'between time'
,
[
date
(
'Y-m-d'
)
.
' 00:00:00'
,
date
(
'Y-m-d'
)
.
' 23:59:59'
])
->
select
();
$num
=
count
(
$send_time
);
//发送数量
$num
=
count
(
$send_time
);
//发送数量
if
(
!
empty
(
$send_time
[
$num
-
1
])
&&
(
time
()
-
strtotime
(
$send_time
[
$num
-
1
]
->
send_time
)
<
58
)
&&
$num
!=
0
)
{
if
(
!
empty
(
$send_time
[
$num
-
1
])
&&
(
time
()
-
strtotime
(
$send_time
[
$num
-
1
]
->
send_time
)
<
58
)
&&
$num
!=
0
)
{
return
'1分钟内不能再次获取验证码'
;
}
if
(
$num
>
7
){
if
(
$num
>
7
)
{
return
'短信发送超过上限'
;
}
$message
=
new
MessageUntils
();
$_code
=
mt_rand
(
1000
,
9999
)
.
''
;
$result
=
$message
->
sendCCPSMS
(
$phone
,
array
(
$_code
,
'5分钟'
),
214759
);
$result
=
$message
->
sendCCPSMS
(
$phone
,
array
(
$_code
,
'5分钟'
),
214759
);
$noteLog
->
phone
=
$phone
;
$noteLog
->
template_msg
=
'【同联商业】您的验证码为'
.
$_code
.
',请于5分钟内正确输入,如非本人操作,请忽略此短信。'
;
$noteLog
->
template_msg
=
'【同联商业】您的验证码为'
.
$_code
.
',请于5分钟内正确输入,如非本人操作,请忽略此短信。'
;
$noteLog
->
code
=
$_code
;
$noteLog
->
send_time
=
date
(
'Y-m-d H:i:s'
);
$result
[
'statusCode'
]
=
0
;
$result
[
'statusCode'
]
=
0
;
if
(
$result
[
'statusCode'
]
==
"000000"
)
{
$noteLog
->
is_success
=
1
;
$noteLog
->
save
();
//todo 存code
$redis_
=
RedisExt
::
getRedis
();
if
(
$redis_
)
{
$redis_
->
set
(
$device_id
,
$_code
,
300
);
}
else
{
session
(
$device_id
,
$_code
);
if
(
$redis_
)
{
$redis_
->
set
(
$device_id
,
$_code
,
300
);
}
else
{
session
(
$device_id
,
$_code
);
}
return
"true"
;
}
else
{
...
...
@@ -172,4 +177,25 @@ class MessageUntils {
return
'发送异常,请联系管理员'
;
}
}
/**
* 验证code
* @param $device_id
* @param $code
* @return bool
*/
public
function
verifyCode
(
string
$device_id
,
int
$code
)
:
bool
{
$redis_
=
RedisExt
::
getRedis
();
if
(
$redis_
)
{
$service_code
=
$redis_
->
get
(
$device_id
,
300
);
}
else
{
$service_code
=
session
(
$device_id
);
}
if
(
$code
==
$service_code
)
{
return
true
;
}
else
{
return
false
;
}
}
}
application/api/untils/WxCallbackUntils.php
View file @
056356b8
...
...
@@ -80,7 +80,8 @@ class WxCallbackUntils
'sex'
=>
$user_info
->
sex
,
'province'
=>
$user_info
->
province
,
'city'
=>
$user_info
->
city
,
'buyer_img'
=>
$user_info
->
headimgurl
'buyer_img'
=>
$user_info
->
headimgurl
,
'union_id'
=>
$user_info
->
unionid
,
);
session
(
"userInfo"
,
$data
);
return
$data
;
...
...
application/api/validate/RegisterValidate.php
View file @
056356b8
...
...
@@ -14,12 +14,15 @@ use think\Validate;
class
RegisterValidate
extends
Validate
{
protected
$rule
=
[
'wx_open_id'
=>
'require|length:10,50'
,
'code'
=>
'require|number'
,
'device_id'
=>
'require'
,
'phone'
=>
[
'regex'
=>
'/^((13[0-9])|(14[0-9])|(15[0-9])|(18[0-9])|(16[0-9])|(17[0-9])|(19[0-9]))\\d{8}$/i'
],
];
protected
$message
=
[
'wx_open_id.require'
=>
'微信open_id不能为空'
,
'wx_open_id.length:10,50'
=>
'微信open_id错误'
,
'phone.regex'
=>
'手机号格式不正确'
,
'device_id.require'
=>
'设备id不能为空'
,
'code.require'
=>
'code为必填字段'
,
...
...
@@ -28,6 +31,6 @@ class RegisterValidate extends Validate
protected
$scene
=
[
'verify'
=>
[
'phone,device_id'
],
'register'
=>
[
'phone,device_id,code'
],
'register'
=>
[
'phone,device_id,code
,wx_open_id
'
],
];
}
\ No newline at end of file
application/api/validate/UWxInfoValidate.php
View file @
056356b8
...
...
@@ -14,26 +14,29 @@ use think\Validate;
class
UWxInfoValidate
extends
Validate
{
protected
$rule
=
[
'wx_open_id'
=>
'require|length:10,50'
,
'sex'
=>
'require|number'
,
'source'
=>
'require|number'
,
'user_id'
=>
'require|number|gt:0'
,
'wx_open_id'
=>
'require|length:10,50'
,
'wx_union_id'
=>
'require|length:10,50'
,
'sex'
=>
'require|number'
,
'source'
=>
'require|number'
,
'user_id'
=>
'require|number|gt:0'
,
];
protected
$message
=
[
'wx_open_id.require'
=>
'微信open_id不能为空'
,
'wx_open_id.length:10,50'
=>
'微信open_id错误'
,
'sex.require'
=>
'性别为必须字段'
,
'sex.number'
=>
'性别必须是数字'
,
'source.require'
=>
'来源为必须字段'
,
'source.number'
=>
'来源必须是数字'
,
'user_id.require'
=>
'user_id为必须字段'
,
'user_id.number'
=>
'user_id必须是数字'
,
'user_id.gt'
=>
'user_id必须大于0'
,
'wx_open_id.require'
=>
'微信open_id不能为空'
,
'wx_open_id.length:10,50'
=>
'微信open_id错误'
,
'wx_union_id.require'
=>
'微信union_id不能为空'
,
'wx_union_id.length:10,50'
=>
'微信union_id错误'
,
'sex.require'
=>
'性别为必须字段'
,
'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'
,
'wx_union_id'
,
'sex'
,
'source'
],
'select'
=>
[
'wx_open_id'
],
'bind'
=>
[
'wx_open_id'
,
'user_id'
],
];
...
...
application/index/controller/WxTest.php
View file @
056356b8
...
...
@@ -35,6 +35,8 @@ class WxTest extends Basic
if
(
!
$userInfo
)
{
$this
->
_wxApi
->
getWxCode
(
$this
->
url
);
}
else
{
dump
(
$userInfo
);
return
view
(
"test"
);
}
}
...
...
application/model/UWxInfo.php
View file @
056356b8
...
...
@@ -68,8 +68,8 @@ class UWxInfo extends Model
*/
public
function
getWxInfoByOpenId
(
string
$open_id
)
{
$where_
[
"wx_
ope
n_id"
]
=
$open_id
;
$where_
[
"is_del"
]
=
0
;
$where_
[
"wx_
unio
n_id"
]
=
$open_id
;
$where_
[
"is_del"
]
=
0
;
return
$this
->
field
(
"id"
)
->
where
(
$where_
)
...
...
@@ -95,6 +95,9 @@ class UWxInfo extends Model
if
(
isset
(
$params
[
"wx_open_id"
]))
{
$arr
[
"wx_open_id"
]
=
$params
[
"wx_open_id"
];
}
if
(
isset
(
$params
[
"wx_union_id"
]))
{
$arr
[
"wx_union_id"
]
=
$params
[
"wx_union_id"
];
}
if
(
isset
(
$params
[
"buyer_nick"
]))
{
$arr
[
"buyer_nick"
]
=
$params
[
"buyer_nick"
];
}
...
...
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