diff --git a/app/common.php b/app/common.php index 04a1053..ffad61d 100755 --- a/app/common.php +++ b/app/common.php @@ -1,3 +1,4 @@ +<<<<<<< HEAD 'wx89c12dd426a55a2e', - 'appSecret' => '33e66bcf944f9810abbb5ddd7825403d', - 'token' => 'cxhxy', - - ]; - - } - - - public function index() - { - if (isset($_GET['echostr'])) { - echo $_GET["echostr"]; - exit; - } - - //接收微信推送数据 - $data = file_get_contents('php://input'); - -// $data = simplexml_load_string($data, "SimpleXMLElement", LIBXML_NOCDATA); - if (!empty($data)) { - $data = json_decode($data, true); - if (!empty($data)) { - //首次关注 - if ($data['Event'] == 'subscribe') { - $user = Db::name('food_user')->where('open_id', $data['FromUserName'])->value('is_new'); - if ($user !== 1) { - //不是新关注 - die('success'); - } else { - - //插入一条新用户数据 - $data = [ - 'open_id' => $data['FromUserName'], - 'platform' => 10, - 'applet_id' => 10001, - 'create_time' => time() - ]; - Db::name('food_user')->insert($data); - //发送公众号消息 - - $wx = new Driver; - $access_token = $wx->getAccessToken(10001); - $url = 'https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token=' . $access_token; - $queryarr = [ - 'msgtype' => 'news', - 'news' => [ - 'articles' => [ - 'title' => '您有一张新的优惠券,请及时领取', - 'picurl' => '', - 'url' => 'https://www.baidu.com', - 'description' => '黄辛一新人优惠,首次关注赠送优惠券' - ] - ] - ]; - $queryarr['touser'] = $data['FromUserName']; - Http::post($url, hema_json($queryarr)); - - } - - die('success'); - } - } - } - - } - - + 'wx89c12dd426a55a2e', + 'appSecret' => '33e66bcf944f9810abbb5ddd7825403d', + 'token' => 'cxhxy', + + ]; + + } + + + public function index() + { + if (isset($_GET['echostr'])) { + echo $_GET["echostr"]; + exit; + } + + //接收微信推送数据 + $data = file_get_contents('php://input'); + +// $data = simplexml_load_string($data, "SimpleXMLElement", LIBXML_NOCDATA); + if (!empty($data)) { + $data = json_decode($data, true); + if (!empty($data)) { + //首次关注 + if ($data['Event'] == 'subscribe') { + $user = Db::name('food_user')->where('open_id', $data['FromUserName'])->value('is_new'); + if ($user !== 1) { + //不是新关注 + die('success'); + } else { + + //插入一条新用户数据 + $data = [ + 'open_id' => $data['FromUserName'], + 'platform' => 10, + 'applet_id' => 10001, + 'create_time' => time() + ]; + Db::name('food_user')->insert($data); + //发送公众号消息 + + $wx = new Driver; + $access_token = $wx->getAccessToken(10001); + $url = 'https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token=' . $access_token; + $queryarr = [ + 'msgtype' => 'news', + 'news' => [ + 'articles' => [ + 'title' => '您有一张新的优惠券,请及时领取', + 'picurl' => '', + 'url' => 'https://www.baidu.com', + 'description' => '黄辛一新人优惠,首次关注赠送优惠券' + ] + ] + ]; + $queryarr['touser'] = $data['FromUserName']; + Http::post($url, hema_json($queryarr)); + + } + + die('success'); + } + } + } + + } } \ No newline at end of file diff --git a/extend/hema/wechat/logs/20231206.log b/extend/hema/wechat/logs/20231206.log new file mode 100644 index 0000000..7db3031 --- /dev/null +++ b/extend/hema/wechat/logs/20231206.log @@ -0,0 +1,12 @@ +[2023-12-06 18:11:51] +222222222222222222 + +[2023-12-06 18:11:51] +{"ToUserName":"gh_f3e7ab01d5bd","FromUserName":"oy5Wi6kx3rPhdeV001GbKcy-P9gk","CreateTime":"1701857511","MsgType":"event","Event":"unsubscribe","EventKey":{}} + +[2023-12-06 18:11:54] +222222222222222222 + +[2023-12-06 18:11:54] +{"ToUserName":"gh_f3e7ab01d5bd","FromUserName":"oy5Wi6kx3rPhdeV001GbKcy-P9gk","CreateTime":"1701857514","MsgType":"event","Event":"subscribe","EventKey":{}} + diff --git a/runtime/cache/eb/300fe116b3568a7e80a6c2812b1a38.php b/runtime/cache/eb/300fe116b3568a7e80a6c2812b1a38.php index e63c99f..32eaf40 100644 --- a/runtime/cache/eb/300fe116b3568a7e80a6c2812b1a38.php +++ b/runtime/cache/eb/300fe116b3568a7e80a6c2812b1a38.php @@ -1,4 +1,4 @@ -1701848041 \ No newline at end of file +1701879149 \ No newline at end of file