wecenter常用方法

wecenter 文章 精帖 2021-03-21 17:06 667 0 全屏看文

AI助手支持GPT4.0

发送微信消息:

$openid = $input_message['fromUsername'];
$this->send_text_message($openid, $response_message);

发送GET或POST请求

HTTP请求
//GET请求
$res =  curl_get_contents($url, $timeout = 30)

//POST请求
$args = array(
	'client_id' => get_setting('sina_akey'),
	'client_secret' => get_setting('sina_skey'),
	'grant_type' => 'authorization_code',
	'code' => $this->authorization_code,
	'redirect_uri' => get_js_url($this->redirect_url)
);

$result = HTTP::request(self::OAUTH2_TOKEN_URL, 'POST', http_build_query($args));

if (!$result)
{
	$this->error_msg = AWS_APP::lang()->_t('获取 access token 时,与微博通信失败');

	return false;
}

Wecenter文章从bbcode到html

$article[$i]['message'] = FORMAT::parse_attachs(nl2br(FORMAT::parse_bbcode($val['message'])));

wecenter调用验证码的方法

前端------------------------------------

首先要引入js

<script src="http://wenda.wecenter.com/static/js/aws.js?v=20160523" type="text/javascript"></script>



然后需要写上img

 <input type="text" style="width:80px" name="vcode" placeholder="验证码" />  <img id="captcha" onclick="this.src = '/account/captcha/'+Math.floor(Math.random() * 10000)" src="">



后端


-------------------------------------

if (!AWS_APP::captcha()->is_validate($_POST['vcode']))
{
   die("captcha error");
}

跳转:

HTTP::redirect($download_link);

设置Cookie

HTTP::set_cookie('fromuid', $_GET['fromuid']);

使用Session存储值

//存值
AWS_APP::session()->alipay_user_id = $user_id;
//取值
AWS_APP::session()->alipay_user_id;

判断是否是苹果设备

private function _do_ismac(){
if(strpos($_SERVER['HTTP_USER_AGENT'], 'Safari') || strpos($_SERVER['HTTP_USER_AGENT'], 'iphone') || strpos($_SERVER['HTTP_USER_AGENT'], 'ipod') || strpos($_SERVER['HTTP_USER_AGENT'], 'ipad')) {
return true;
}
return false;
}

删除过期文件

private function _do_kill($path,$timeOutSec){
ignore_user_abort();
if (!strpos($path, '.')) return;
$mtime=filemtime($path); 
$now=time(); 
if(is_file($path) && ($now-$mtime) > $timeOutSec){ 
unlink($path); 
}
}

登录成功写入cookie(短信登录会用到)

HTTP::set_cookie('_user_login', get_login_cookie_hash($user_info['user_name'], $user_info['password'], $user_info['salt'], $user_info['uid'], false));

设置Cookie

HTTP::set_cookie('_user_login', "", false));

获取用户ID,并判断是不是管理

if ($article_info['uid'] != $this->user_id AND !$this->user_info['permission']['is_administortar'] AND !$this->user_info['permission']['is_moderator'])
{
     H::ajax_json_output(AWS_APP::RSM(null, '-1', AWS_APP::lang()->_t('你没有权限编辑这个附件列表')));
 }

数据库操作:

<?php
if (!defined('IN_ANWSION'))
{
die;
}

class pay_class extends AWS_MODEL
{
public function update_trade_status($data)
{	

$this->shutdown_query("UPDATE " . get_table('users') . ' SET online_time = online_time + ' . intval($online_time) . ', last_active = ' . time() . ' WHERE uid = ' . intval($uid));

return true;
}

public function get_trade_by_tradeno($tradeno)
{
return $this->fetch_row('media_convert', "out_trade_no = '$tradeno'"  );
}

public function get_recommend_topic_id_title(){
		return $this->query_all('select id,title from aws_article where is_recommend = 1 limit 5'); 
	}

public function update_trade($trade)
{
return $this->update('pages', array(
'title' => $title,
'keywords' => $keywords,
'description' => $description,
'contents' => $contents,
'url_token' => $url_token
), 'id = ' . intval($id));
}

public function add_trade($trade)
{
return $this->insert('pages', array(
'title' => $title,
'keywords' => $keywords,
'description' => $description,
'contents' => $contents,
'url_token' => $url_token
));
}

public function delete_expire_users()
{	
return $this->delete('users_online', 'last_active < ' . (time() - 1800));
}
}


缓存调用

//增加缓存
$result_cache_key = 'article_list_by_topic_ids_' . md5(implode('_', $topic_ids) . $order_by . $page . $per_page);
if (!$result = AWS_APP::cache()->get($result_cache_key)){
    AWS_APP::cache()->set($result_cache_key, $result, get_setting('cache_level_high')); //缓存时间是秒
}

//删除缓存
AWS_APP::cache()->delete($result_cache_key);
-EOF-

AI助手支持GPT4.0