<?php
/**
* Created by PhpStorm.
* Power by Mikkle
* QQ:776329498
* Date: 2017年4月27日
* Time: 13:33
*/
namespace app\center\controller;
use app\base\controller\Curl;
use app\base\controller\Rsa;
use app\base\model\we\WeFans;
use app\base\model\we\WeLocation;
use app\base\model\we\WeMessage;
use app\base\model\we\WeTemplateMessage;
use mikkle\tp_wechat\WechatApi;
use think\Db;
use think\Exception;
use think\Cache;
use think\Log;
class ErpApi extends WechatApi
{
protected $valid = false; //网站第一次匹配 true 1为匹配
protected $isHook = false; //是否开启钩子
public function index()
{
try{
// Log::notice($this->request);
parent::index();
}catch (Exception $e){
Log::error($e->getMessage());
}
}
protected function messageApplyEvent($EventKey, $subscribe = false){
$news_array = [
[
'Title' => '申请云管家ERP系统',
'Description' => '现在去申请',
'PicUrl' => '',
'Url' => $this->request->domain() . '/center/apply/apply?event_key=' . $EventKey,
],
];
$reply = ['type' => 'news', 'message' => $news_array];
return $reply;
}
/**
* 微信API接口 扫码登录
* Power by Mikkle
* QQ:776329498
* @param $EventKey
* @param bool|false $subscribe
* @return array
*/
protected function messageLogEvent($EventKey, $subscribe = false)
{
$domain =Db::table("mk_we_fans_domain")->where(["status"=>1,"openid"=>$this->openid])->value("domain");
if ($domain) {
//写入登录缓存
$log_data = [
'code' => 1001,
'content' => '登录成功',
'data' => $this->openid,
];
// Cache::set('log_' . $EventKey, $log_data, 120);
$open_id = Rsa::instance()->encrypt($this->openid);
try {
$url = "http://{$domain}/api/system/loginWechat";
$push_data = [
"open_id" => $open_id,
"event_key" => $EventKey
];
$result_code = json_decode(Curl::curlPost($url, $push_data));
if (!is_object($result_code)) {
$result_code = json_decode(Curl::curlPost($url, $push_data));
}
if (is_object($result_code)) {
if (isset($result_code->code)) {
if ($result_code->code == 1001) {
if ($subscribe) {
$reply = ['type' => 'text', 'message' => '感谢你的关注,你正在进行微信扫码成功.登录ID[' . $EventKey . ']'];
} else {
$reply = ['type' => 'text', 'message' => '你正在进行微信扫码.登录ID[' . $EventKey . ']'];
}
}else{
throw new Exception($result_code);
}
}
}else{
throw new Exception($result_code);
}
}catch (Exception $e){
Log::error($e->getMessage());
$reply=['type' => 'text', 'message' => '感谢你的关注'];
return $reply;
}
} else {
$news_array = [
[
'Title' => '你的微信暂时未绑定ERP系统',
'Description' => '现在去绑定',
'PicUrl' => '',
'Url' => $this->request->domain() . '/center/we_action/binding?sid=' . $EventKey,
],
];
$reply = ['type' => 'news', 'message' => $news_array];
}
return $reply;
}
ThinkPHP 是一个免费开源的,快速、简单的面向对象的 轻量级PHP开发框架 ,创立于2006年初,遵循Apache2开源协议发布,是为了敏捷WEB应用开发和简化企业应用开发而诞生的。ThinkPHP从诞生以来一直秉承简洁实用的设计原则,在保持出色的性能和至简的代码的同时,也注重易用性。并且拥有众多的原创功能和特性,在社区团队的积极参与下,在易用性、扩展性和性能方面不断优化和改进,已经成长为国内最领先和最具影响力的WEB应用开发框架,众多的典型案例确保可以稳定用于商业以及门户级的开发。