1
This commit is contained in:
parent
86cd185669
commit
c188bb96cb
@ -42,11 +42,11 @@ class Index
|
|||||||
//接收微信推送数据
|
//接收微信推送数据
|
||||||
$data = file_get_contents('php://input');
|
$data = file_get_contents('php://input');
|
||||||
|
|
||||||
// $data = simplexml_load_string($data, "SimpleXMLElement", LIBXML_NOCDATA);
|
$data = simplexml_load_string($data, "SimpleXMLElement", LIBXML_NOCDATA);
|
||||||
if (!empty($data)) {
|
if (!empty($data)) {
|
||||||
// $data = json_decode(json_encode($data), true);
|
$data = json_decode(json_encode($data), true);
|
||||||
|
|
||||||
$data = json_decode($data, true);
|
// $data = json_decode($data, true);
|
||||||
$openid = $data['FromUserName'];
|
$openid = $data['FromUserName'];
|
||||||
$wx = new Driver;
|
$wx = new Driver;
|
||||||
$access_token = $wx->getWxAccessToken(10001, $openid);
|
$access_token = $wx->getWxAccessToken(10001, $openid);
|
||||||
@ -56,7 +56,7 @@ class Index
|
|||||||
|
|
||||||
//首次关注
|
//首次关注
|
||||||
if ($data['Event'] == 'subscribe') {
|
if ($data['Event'] == 'subscribe') {
|
||||||
$user = Db::name('user_wx')->where('open_id', $openid)->value('is_new');
|
$user = Db::name('user_wx')->where('wx_openid', $openid)->value('is_new');
|
||||||
|
|
||||||
if (!empty($user) && $user !== 1) {
|
if (!empty($user) && $user !== 1) {
|
||||||
//不是新关注
|
//不是新关注
|
||||||
@ -64,13 +64,17 @@ class Index
|
|||||||
} else {
|
} else {
|
||||||
if (empty($user)) {
|
if (empty($user)) {
|
||||||
|
|
||||||
$wx_url = 'https://api.weixin.qq.com/cgi-bin/user/info?access_token=' . $access_token . 'openid=' . $openid . '&lang=zh_CN';
|
$wx_url = 'https://api.weixin.qq.com/cgi-bin/user/info?access_token=' . $access_token . '&openid=' . $openid . '&lang=zh_CN';
|
||||||
$info = Http::get($wx_url);
|
$info = Http::get($wx_url);
|
||||||
|
$info=json_decode($info,true);
|
||||||
|
|
||||||
|
|
||||||
$unionid = $info['unionid'];
|
$unionid = $info['unionid'];
|
||||||
|
|
||||||
|
|
||||||
//插入一条新用户数据
|
//插入一条新用户数据
|
||||||
$data = [
|
$data = [
|
||||||
'wx_open_id' => $openid,
|
'wx_openid' => $openid,
|
||||||
'unionid' => $unionid,
|
'unionid' => $unionid,
|
||||||
'create_time' => time()
|
'create_time' => time()
|
||||||
];
|
];
|
||||||
@ -97,7 +101,7 @@ class Index
|
|||||||
Db::name('food_coupon_user_wx')->insert($data1);
|
Db::name('food_coupon_user_wx')->insert($data1);
|
||||||
Db::name('food_coupon_user_wx')->insert($data2);
|
Db::name('food_coupon_user_wx')->insert($data2);
|
||||||
Db::commit();
|
Db::commit();
|
||||||
die('success');
|
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
Db::rollback();
|
Db::rollback();
|
||||||
write_log(json_encode($e->getMessage()), __DIR__);
|
write_log(json_encode($e->getMessage()), __DIR__);
|
||||||
@ -105,6 +109,9 @@ class Index
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//发送公众号消息
|
//发送公众号消息
|
||||||
$url = 'https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token=' . $access_token;
|
$url = 'https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token=' . $access_token;
|
||||||
$queryarr = [
|
$queryarr = [
|
||||||
|
|||||||
3
extend/hema/wechat/logs/20231207.log
Normal file
3
extend/hema/wechat/logs/20231207.log
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
[2023-12-07 16:46:49]
|
||||||
|
"{\"errcode\":0,\"errmsg\":\"ok\"}"
|
||||||
|
|
||||||
Loading…
x
Reference in New Issue
Block a user