1
This commit is contained in:
parent
d90717879c
commit
17365e65a1
@ -1,4 +1,3 @@
|
|||||||
<<<<<<< HEAD
|
|
||||||
<?php
|
<?php
|
||||||
/**
|
/**
|
||||||
* 应用公共函数库文件
|
* 应用公共函数库文件
|
||||||
|
|||||||
@ -1781,22 +1781,27 @@ class Driver
|
|||||||
if ($applet = Applet::getApplet(['applet_id' => $applet_id, 'status' => 1])) {
|
if ($applet = Applet::getApplet(['applet_id' => $applet_id, 'status' => 1])) {
|
||||||
$access_token = $applet['access_token'];
|
$access_token = $applet['access_token'];
|
||||||
|
|
||||||
if (empty($access_token)) {
|
if ($type == 1) {
|
||||||
|
$appid = 'wx3668302906e3894f';
|
||||||
|
$app_secret = '3ef948febd085fb89908f22b4a79c52f';
|
||||||
|
} else {
|
||||||
|
$appid = 'wx89c12dd426a55a2e';
|
||||||
|
$app_secret = '33e66bcf944f9810abbb5ddd7825403d';
|
||||||
|
}
|
||||||
|
|
||||||
if (time() > $applet['expires_in']) {
|
|
||||||
$url = 'https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=wx3668302906e3894f&secret=3ef948febd085fb89908f22b4a79c52f';
|
|
||||||
$result = json_decode(Http::get($url), true);
|
|
||||||
|
|
||||||
if (isset($result['access_token'])) {
|
if (empty($access_token) || time() > $applet['expires_in']) {
|
||||||
$access_token = $result['access_token'];
|
$url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=$appid&secret=$app_secret";
|
||||||
$applet->access_token = $result['access_token'];
|
$result = json_decode(Http::get($url), true);
|
||||||
$applet->expires_in = time() + 3600;//2个小时候过期,这里设置1小时获取一次
|
|
||||||
$applet->save();//保存最新的令牌access_token和过期时间
|
if (isset($result['access_token'])) {
|
||||||
}
|
$access_token = $result['access_token'];
|
||||||
} else {
|
$applet->access_token = $result['access_token'];
|
||||||
return $access_token;
|
$applet->expires_in = time() + 3600;//2个小时候过期,这里设置1小时获取一次
|
||||||
|
$applet->save();//保存最新的令牌access_token和过期时间
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return $access_token;
|
||||||
|
|
||||||
}
|
}
|
||||||
return $access_token;
|
return $access_token;
|
||||||
|
|||||||
@ -44,30 +44,38 @@ class Index
|
|||||||
|
|
||||||
// $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($data, true);
|
$data = json_decode($data, true);
|
||||||
|
$openid = $data['FromUserName'];
|
||||||
|
|
||||||
if (!empty($data)) {
|
if (!empty($data)) {
|
||||||
//首次关注
|
//首次关注
|
||||||
if ($data['Event'] == 'subscribe') {
|
if ($data['Event'] == 'subscribe') {
|
||||||
$user = Db::name('food_user')->where('open_id', $data['FromUserName'])->value('is_new');
|
$user = Db::name('food_user')->where('open_id', $openid)->value('is_new');
|
||||||
if ($user !== 1) {
|
|
||||||
|
if (!empty($user) && $user !== 1) {
|
||||||
//不是新关注
|
//不是新关注
|
||||||
die('success');
|
die('success');
|
||||||
} else {
|
} else {
|
||||||
|
if (empty($user)) {
|
||||||
|
//插入一条新用户数据
|
||||||
|
$data = [
|
||||||
|
'open_id' => $openid,
|
||||||
|
'platform' => 10,
|
||||||
|
'applet_id' => 10001,
|
||||||
|
'create_time' => time()
|
||||||
|
];
|
||||||
|
Db::name('food_user')->insert($data);
|
||||||
|
}
|
||||||
|
|
||||||
//插入一条新用户数据
|
|
||||||
$data = [
|
|
||||||
'open_id' => $data['FromUserName'],
|
|
||||||
'platform' => 10,
|
|
||||||
'applet_id' => 10001,
|
|
||||||
'create_time' => time()
|
|
||||||
];
|
|
||||||
Db::name('food_user')->insert($data);
|
|
||||||
//发送公众号消息
|
//发送公众号消息
|
||||||
|
|
||||||
$wx = new Driver;
|
$wx = new Driver;
|
||||||
$access_token = $wx->getAccessToken(10001);
|
$access_token = $wx->getAccessToken(10001, 2);
|
||||||
$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 = [
|
||||||
|
'touser' => $openid,
|
||||||
'msgtype' => 'news',
|
'msgtype' => 'news',
|
||||||
'news' => [
|
'news' => [
|
||||||
'articles' => [
|
'articles' => [
|
||||||
@ -78,9 +86,8 @@ class Index
|
|||||||
]
|
]
|
||||||
]
|
]
|
||||||
];
|
];
|
||||||
$queryarr['touser'] = $data['FromUserName'];
|
$result = Http::post($url, hema_json($queryarr));
|
||||||
Http::post($url, hema_json($queryarr));
|
write_log($result, __DIR__);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
die('success');
|
die('success');
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user