1 Star 1 Fork 0

天明/myClass

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
ModelController.php 7.48 KB
一键复制 编辑 原始数据 按行查看 历史
小天明 提交于 2016-04-21 17:32 . kongzhiqi
<?php
namespace app\modules\share\controllers;
use common\extend\Wechats;
use unity\mySocket;
use Yii;
use common\extend\Caches;
class ModelController extends \app\modules\share\controllers\IndexController
{
public $enableCsrfValidation = false;
//获取带参数的二维码信息
public function actionGetimg(){
$request = Yii::$app->request;
$weObj = new wechats($this->actionConfig());
$scene = isset($_GET['scene'])?$_GET['scene']:'';
$callback = isset($_GET['callback'])?$_GET['callback']:'';
if (!empty($scene) && strlen($scene) == 32) {
$temp = md5(time() . sha1(time())) . uniqid();//随机文件名
$scene_id = substr(strtr($temp, 0, 1), 0, 32);//32位的非0整形
$scene_Temp = htmlentities(isset($_GET['scene'])?$_GET['scene']:'');
$scene = isset($scene_Temp)?$scene_Temp:$scene_id;//唯一令牌ID
$time = htmlentities(isset($_GET['time'])?$_GET['time']:'');
$time = isset($time)?$time:1800; //过期时间
$imgData = $weObj->getQRCode($scene, 0, $time);
$Socket = new mySocket();
$Guid_data = array('openId'=>md5($imgData['ticket']),'content'=>$scene,'second'=>3600); //缓存数据
$Socket->send('4016',$Guid_data);
$img = $weObj->getQRUrl($imgData['ticket']);
$arr = array('img' => $img, 'scene' => $Guid_data, 'time' => time()+$time,'code'=>1);
if(empty($callback)) {
return ajaxReturn($arr); //非jsonp形式 返回json数据
}else{
echo $callback.'('.json_encode($arr).')';//如果使用jsonp方式请求
}
}else{
$arr = array('message'=>'请求参数有误','code' => -1);
if(empty($callback)) {
return ajaxReturn($arr);
}else{
echo $callback.'('.json_encode($arr).')';//如果使用jsonp方式请求
}
}
}
/** 简单的邮件提醒
* @param $title 标题
* @param $content 内容
* @param $to 发给谁
*/
public function SendMail($title,$content,$to='iyahe@qq.com'){
$SendData = array(
'title'=>$title,
'content'=>$content,
'to'=>$to,
'come'=>'快有家测试',
'url'=>__PATHS__,
);
$result= https_request('http://api.he29.com/index.php/api/mail',$SendData);
}
//设计菜单
public function actionSetmenu(){
$username = isset($_GET['u'])?$_GET['u']:'';
$token = isset($_GET['token'])?$_GET['token']:'';
if ($username == 'admin' && $token == md5('自定义菜单')) {
$weObj = new wechats($this->actionConfig());
$data = array (
'button' => array (
0 => array (
'name' => '我是租客',
'sub_button' => array (
0 => array (
'type' => 'view',
'name' => '提交租房需求',
'url' => 'http://w.url.cn/s/Ay6QQuX',
),
// 1 => array (
// 'type' => 'view',
// 'name' => '富租金',
// 'url' => 'http://w.url.cn/s/Aw5ioUQ',
// ),
1 => array (
'type' => 'view',
'name' => '一元划算',
'url' => 'http://w.url.cn/s/Amio5B1',
),
),
),
1 => array (
'name' => '我是房东',
'sub_button' => array (
0 => array (
'type' => 'view',
'name' => '发布房源',
'url' => 'http://w.url.cn/s/A1Apsqb',
),
1 => array (
'type' => 'click',
'name' => '社区联络员',
'key' => 'BT_LIAISON',
),
),
),
2 => array (
'name' => '更多活动',
'sub_button' => array (
0 => array (
'type' => 'view',
'name' => '中国好房东',
'url' => 'http://w.url.cn/s/AEibhM4',
),
1 => array (
'type' => 'view',
'name' => '加入会员',
'url' => 'http://w.url.cn/s/Aj9DuGO',
),
2 => array (
'type' => 'view',
'name' => 'APP下载',
'url' => 'http://w.url.cn/s/AEOVCA3',
),
3 => array (
'type' => 'click',
'name' => '联系客服',
'key' => 'BT_CURSTOMER',
),
),
),
),
);
$result = $weObj->createMenu($data);
P($result);
}else{
echo '(✿◡‿◡)';
}
}
/*短网址生成*/
public function actionUrlCreat(){
$weObj = new wechats($this->actionConfig());
$path = isset($_GET['url'])?$_GET['url']:'';
if(empty($path)) return false;
$result = $weObj->getShortUrl($path);
p($result);
}
/*设置cookie信息['一元划算使用中...']*/
public function actionLogin(){
$url=__PATHS__;//获取当前页面的url
if (empty($_SESSION['userinfo'])) {
$info = $this->actionGetinfo($url);
}else{
$info = $_SESSION['userinfo'];
}
setcookie("UserInfo",json_encode($info),time()+3600*12,'/','.kuaiyoujia.com');
}
/*accesstoken 写入token 到文件*/
public function actionWritetoken(){
$username = isset($_GET['u'])?$_GET['u']:'';
$token = isset($_GET['token'])?$_GET['token']:'';
$write = isset($_GET['w'])?$_GET['w']:'';
$cache = new Caches();
if ($username == 'admin' && $token == md5('快有家')) {
$appid = $this->actionConfig()['appid'];
$appsecret = $this->actionConfig()['appsecret'];
$url = 'https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid='.$appid.'&secret='.$appsecret;
$result = https_request($url);
$tokenData = json_decode($result,true);
/*写入获取日志*/
$this->SetWriteLog($tokenData,'RobotGetAccessToken.txt');
if($tokenData['expires_in'] > 0){
$tokenData['time'] = time()+$tokenData['expires_in'];
$tokenData['date'] = date('Y-m-d H:i:s',$tokenData['time']);
$cache->add('getaccesstoken',json_encode($tokenData));//缓存防止多次重复获取
if($write != '' && $write == 1){
p(file_put_contents($_SERVER['DOCUMENT_ROOT'].'/config/access_token.json',json_encode($tokenData)));
}else{
ajaxReturn($tokenData);
}
}
}else{
echo '(✿◡‿◡)';
}
}
/*获取jstick*/
public function actionWritejsticket(){
$username = isset($_GET['u'])?$_GET['u']:'';
$token = isset($_GET['token'])?$_GET['token']:'';
$write = isset($_GET['w'])?$_GET['w']:'';
$cache = new Caches();
if ($username == 'admin' && $token == md5('快有家')) {
$weObj = new wechats($this->actionConfig());
$access_token = $weObj->checkAuth();
/*获取缓存里面的数据,如果半小时内再次请求,直接返回缓存的数据*/
$url = 'https://api.weixin.qq.com/cgi-bin/ticket/getticket?access_token='.$access_token.'&type=jsapi';
$result = https_request($url);
$jstickData = json_decode($result,true);
/*写入获取日志*/
$this->SetWriteLog($jstickData,'RobotGetJstick.txt');
if($jstickData['expires_in'] > 0){
$jstickData['time'] = time()+$jstickData['expires_in'];
$jstickData['date'] = date('Y-m-d H:i:s',$jstickData['time']);
$jstickData['jsapi_ticket'] = $jstickData['ticket'];
$cache->add('getjsticket',json_encode($jstickData));//缓存防止多次重复获取
if($write != '' && $write == 1){
p(file_put_contents($_SERVER['DOCUMENT_ROOT'].'/config/jsapi_ticket.json',json_encode($jstickData)));
}else{
ajaxReturn($jstickData);
}
}
}else{
echo '(✿◡‿◡)';
}
}
/*传入文件和文件名*/
public function SetWriteLog($tokenData,$name){
$logArr = array(
'comeIp'=>$_SERVER["REMOTE_ADDR"],//来源ip
'time'=>date('Y-m-d H:i:s',time()),
'results'=>$tokenData,
);
Setlog($name,json_encode($logArr),'json');
}
public function actionTest(){
$this->SendMail('快有家'.isPrev().'token文件读取异常','文件内容为:'.'123'); //发送邮件提醒
$urls = 'http://'.isPrev().'/index.php/share/model/writetoken?u=admin&token='.md5('快有家').'&w=1';
https_request($urls);//重新写入刷新token文件
}
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/shala/myClass.git
git@gitee.com:shala/myClass.git
shala
myClass
myClass
master

搜索帮助