public function subscribe($jumpurl, $request)
{
if (empty(session('wxopenid'))) {
//获取用户openid
$baseurl = (is_ssl() ? 'https://' : 'http://') . $_SERVER['HTTP_HOST'] . url('hiv/choose/oauth');
$url = (is_ssl() ? 'https://' : 'http://') . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
header("Location:" . $baseurl . '?url=' . $url);
} else {
//判断用户是否关注
$access_token = 'https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=' . $this->appid . '&secret=' . $this->appsecret;
$access_msg = json_decode(file_get_contents($access_token), true);
$token = $access_msg['access_token'];
$subscribe_msg = "https://api.weixin.qq.com/cgi-bin/user/info?access_token=" . $token . "&openid=" . session('wxopenid');
$subscribe = json_decode(file_get_contents($subscribe_msg), true);
//查询机器的返现金额
$fxmoney = $this->wlgetCol('machine', array('machinenum' => $request[0], 'state' => 1), 'money');
if (empty($fxmoney)) {
exit("<script>alert('这台机器不可使用');window.history.back(-1);</script>");
}
//数据
$data = array(
'uid' => $this->uid,
'openid' => $this->wxopenid,
'machinenum' => $request[0],
'addtime' => time(),
'pay' => 0,
'sbtype' => $request[1],
'oid' => 0,
'down' => 0,
'idcard' => 0,
'fxmoney' => $fxmoney
);
if ($subscribe['subscribe'] == 1) {
$data['new'] = 1;
$this->wladdOne('equipment', $data);
//已关注
header("Location:" . $jumpurl);
} else {
$data['new'] = 0;
$this->wladdOne('equipment', $data);
//未关注
$url = (is_ssl() ? 'https://' : 'http://') . $_SERVER['HTTP_HOST'] . url('Wl/Choose/subscribe');
header("Location:" . $url);
}
}
}