edit-sylive-wx_auth

This commit is contained in:
lccsw
2022-10-10 20:35:54 +08:00
committed by lccsw
parent 0c67382dcc
commit 4961848b90
3 changed files with 63 additions and 11 deletions
+61 -9
View File
@@ -5,6 +5,7 @@ require_once 'Common.php';
class Act extends Wx {
private $group_id;
private $secretkey = '7a23vx9257';
public function __construct(){
parent::__construct();
@@ -31,6 +32,7 @@ class Act extends Wx {
if(!$row){
throw new Hd_exception('参数错误',400);
}
$user = $this->user_model->get(['userId'=>$this->uid],'unionid,nickname,headimg');
$timeStart = strtotime($row['timeStart']);
$info['s_time'] = time() < $timeStart ? $timeStart-time() : 0;
$info['bg'] = $row['bgImg'] ? build_qiniu_image_url($row['bgImg']) : '';
@@ -41,11 +43,16 @@ class Act extends Wx {
if ($re_s) {
$subscribemsg = '已订阅直播';
} else {
$this->load->config('wechat');
$config = $this->config->item('liche');
$sub_redirect_url = urlencode(http_host_com('home') . '/h5/market/sylive/act/subscribemsg?skey=' . $skey
. '&s_time=' . $row['timeStart']);
$subscribemsg = "https://mp.weixin.qq.com/mp/subscribemsg?action=get_confirm&appid={$config['appid']}&scene=0&template_id=sdJ4eXXA3OdMZVkJdOrzusYLGr0Jpz9I7WiZurgGLBs&redirect_url={$sub_redirect_url}&reserved=test#wechat_redirect";
if(!$user['nickname'] && !$user['headimg']){
$sub_redirect_url = http_host_com('home')."/h5/market/sylive/act/userinfo?skey={$skey}&type=sub";
}else{
$this->load->config('wechat');
$config = $this->config->item('liche');
$sub_redirect_url = urlencode(http_host_com('home') . '/h5/market/sylive/act/subscribemsg?skey=' . $skey
. '&s_time=' . $row['timeStart']);
$subscribemsg = "https://mp.weixin.qq.com/mp/subscribemsg?action=get_confirm&appid={$config['appid']}&scene=0&template_id=sdJ4eXXA3OdMZVkJdOrzusYLGr0Jpz9I7WiZurgGLBs&redirect_url={$sub_redirect_url}&reserved=test#wechat_redirect";
}
}
//浏览
$params = array('a_id' => $a_id, 'uid' => $this->uid,'cf_uid' => $act_user['channelId'], 'kpi' => 'browse');
@@ -74,7 +81,6 @@ class Act extends Wx {
"url" => $share_url
);
//直播参数
$user = $this->user_model->get(['userId'=>$this->uid],'unionid,nickname,headimg');
// $live_user = ['userId' => $user['unionid'], 'userName' => $user['nickname'], 'pic' => $user['headimg']];
// $this->load->library('PolyvApi');
// $polyv = new PolyvApi(['channel_id'=>$row['channelId']]);
@@ -91,11 +97,14 @@ class Act extends Wx {
$info['statisticsurl'] = '/h5/market/sylive/stic?skey='.$info['skey'];
$info['channelImg'] = build_qiniu_image_url($row['channelImg']);
// $info['live_url'] = 'https://live.liche.cn/watch/'.$row['channelId'];
$secretkey = '7a23vx9257';
$userid = $user['unionid'] ? $user['unionid'] : $this->uid;
$ts = time()*1000;
$sign = md5($secretkey.$userid.$secretkey.$ts);
$info['live_url'] = "https://live.liche.cn/watch/{$row['channelId']}?userid={$userid}&ts={$ts}&sign={$sign}";
$sign = md5($this->secretkey.$userid.$this->secretkey.$ts);
if(!$user['nickname'] && !$user['headimg']){
$info['live_url'] = http_host_com('home').'/h5/market/sylive/act/userinfo?skey='.$skey;
}else{
$info['live_url'] = "https://live.liche.cn/watch/{$row['channelId']}?userid={$userid}&ts={$ts}&sign={$sign}";
}
$this->data['info'] = $info;
$this->data['sign_package'] = $sign_package;
$this->data['share'] = $share;
@@ -375,4 +384,47 @@ class Act extends Wx {
return ['code'=>0,'data'=>[],'msg'=>$msg];
}
}
//获取微信用户信息
public function userinfo(){
$ret = $this->set_auth('',1);
if($ret){
$update = [
"sex" => $ret['sex'] ? 1 : 0,
];
$ret['nickname'] && $update['nickname'] = strval($ret['nickname']);
$ret['headimgurl'] && $update['headimg'] = strval($ret['headimgurl']);
$ret['unionid'] && $update['unionid'] = $ret['unionid'];
$this->user_model->update($update,['userId'=>$this->uid]);
}
$skey = $this->input->get('skey');
$type = $this->input->get('type');
if (!$skey) {
throw new Hd_exception("参数错误", 400);
}
$param = $this->myencryption->base64url_decode($skey);
$a_id = intval($param['a_id']);//活动id
if (!$a_id) {
throw new Hd_exception("参数错误", 400);
}
$row = $this->market_sylive_activity_model->get(['activityId'=>$a_id]);
if(!$row){
throw new Hd_exception('参数错误',400);
}
if($type=='sub'){ //订阅跳转
$this->load->config('wechat');
$config = $this->config->item('liche');
$sub_redirect_url = urlencode(http_host_com('home') . '/h5/market/sylive/act/subscribemsg?skey=' . $skey
. '&s_time=' . $row['timeStart']);
$subscribemsg = "https://mp.weixin.qq.com/mp/subscribemsg?action=get_confirm&appid={$config['appid']}&scene=0&template_id=sdJ4eXXA3OdMZVkJdOrzusYLGr0Jpz9I7WiZurgGLBs&redirect_url={$sub_redirect_url}&reserved=test#wechat_redirect";
redirect($subscribemsg);
}else{
$user = $this->user_model->get(['userId'=>$this->uid],'unionid,nickname,headimg');
$userid = $user['unionid'] ? $user['unionid'] : $this->uid;
$ts = time()*1000;
$sign = md5($this->secretkey.$userid.$this->secretkey.$ts);
$live_url = "https://live.liche.cn/watch/{$row['channelId']}?userid={$userid}&ts={$ts}&sign={$sign}";
redirect($live_url);
}
}
}
+1 -1
View File
@@ -136,7 +136,7 @@ class Wx extends Common{
public function _remap($method){
try{
if(!in_array($method,$this->white_login_method) && !$this->uid){
$ret = $this->set_auth('',1);
$ret = $this->set_auth();
$openid = $ret['openid'];
$row_wechat = $this->user_model->get(['openid' => $openid,'status>='=>0]);
if($row_wechat['status']){
+1 -1
View File
@@ -91,4 +91,4 @@ class Login extends CI_Controller{
$_SESSION['market_sylive_session'] = '';
$this->show_json('',200, '退出成功');
}
}
}