Exemple #1
0
 private function getJsApiTicket()
 {
     global $_W;
     $data = array();
     $wechat = pdo_fetch("SELECT access_token FROM " . tablename('wechats') . " WHERE weid = {$_W['weid']}");
     $AccessToken = iunserializer($wechat['access_token']);
     $now = time();
     if ($AccessToken['expire'] < $now || !$AccessToken['ticket']) {
         //失效时,从服务器获取最新的access_token和ticket
         $res = ihttp_get("https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid={$this->appId}&secret={$this->appSecret}");
         $content = @json_decode($res['content'], true);
         $access_token = $content['access_token'];
         $res1 = ihttp_get("https://api.weixin.qq.com/cgi-bin/ticket/getticket?type=jsapi&access_token={$access_token}");
         $content1 = @json_decode($res1['content'], true);
         $ticket = $content1['ticket'];
         $data['token'] = $access_token;
         $data['expire'] = $now + 7000;
         //是7200秒失效,这里取7000
         $data['ticket'] = $ticket;
         pdo_update("wechats", array('access_token' => serialize($data)), array('weid' => $_W['weid']));
     } else {
         $ticket = $AccessToken['ticket'];
     }
     return $ticket;
 }
 public function getJsApiTicket()
 {
     if (!empty($_W['account']['jsapi_ticket']) && is_array($_W['account']['jsapi_ticket']) && !empty($_W['account']['jsapi_ticket']['ticket']) && !empty($_W['account']['jsapi_ticket']['expire']) && $_W['account']['jsapi_ticket']['expire'] > TIMESTAMP) {
         return $_W['account']['jsapi_ticket']['ticket'];
     }
     load()->func('communication');
     $access_token = $this->getAccessToken();
     if (is_error($access_token)) {
         return $access_token;
     }
     $url = "https://api.weixin.qq.com/cgi-bin/ticket/getticket?access_token={$access_token}&type=jsapi";
     $content = ihttp_get($url);
     if (is_error($content)) {
         return error(-1, '调用接口获取微信公众号 jsapi_ticket 失败, 错误信息: ' . $content['message']);
     }
     $result = @json_decode($content['content'], true);
     if (empty($result) || intval($result['errcode']) != 0 || $result['errmsg'] != 'ok') {
         return error(-1, '获取微信公众号 jsapi_ticket 结果错误, 错误信息: ' . $result['errmsg']);
     }
     $record = array();
     $record['ticket'] = $result['ticket'];
     $record['expire'] = TIMESTAMP + $result['expires_in'] - 200;
     $row = array();
     $row['jsapi_ticket'] = iserializer($record);
     pdo_update('account_wechats', $row, array('acid' => $_W['account']['acid']));
     $_W['account']['jsapi_ticket'] = $record;
     return $record['ticket'];
 }
Exemple #3
0
 public function getUserInfo($access_token, $openid)
 {
     $api_url = "https://api.weixin.qq.com/cgi-bin/user/info?access_token=" . $access_token . "&openid=" . $openid . "&lang=zh_CN";
     $content = ihttp_get($api_url);
     $userInfo = @json_decode($content['content'], true);
     return $userInfo;
 }
Exemple #4
0
 public function respond()
 {
     $content = $this->message['content'];
     global $_W;
     if (!$this->inContext) {
         $this->beginContext(60);
         return $this->respText('点击下方的“+”,发送您的地理位置。然后我们会返回您周边的酒店!');
     } else {
         if (isset($this->message['location_x']) && isset($this->message['location_y'])) {
             $this->endContext();
             load()->func('communication');
             $data = ihttp_get("http://api.map.baidu.com/telematics/v3/local?location={$this->message['location_y']},{$this->message['location_x']}&keyWord=酒店&output=json&ak=jhSS7UjKAS9P9h2vDfhacjmr");
             $data = json_decode($data['content'], true);
             if ($data['status'] === 'Success') {
                 foreach ($data['pointList'] as $key => $val) {
                     if ((int) $key > 7) {
                         break;
                     }
                     $return[] = array('title' => $val['name'], 'description' => $val['address'], 'picurl' => '', 'url' => $val['additionalInformation']['link'][0]['url']);
                 }
                 return $this->respNews($return);
             } else {
                 return $this->respText("没有查询结果。");
             }
         } else {
             $this->endContext();
         }
         return false;
     }
 }
 private function GetRouterInter($iur, $appid, $appkey, $nodeid, $openid)
 {
     $arrResult = array('flag' => 0, 'result' => '', 'token' => '', 'debug' => '');
     $url = "{$iur}?appId={$appid}&appKey={$appkey}&nodeId={$nodeid}&openId={$openid}";
     $rsp = ihttp_get($url);
     $dat = $rsp['content'];
     //获取接口情况
     if (!empty($dat)) {
         $result = json_decode($dat, true);
         if (!is_array($result)) {
             $arrResult['flag'] = 0;
             $arrResult['result'] = '接口返回参数不是JSON格式';
             $arrResult['debug'] = $dat;
         } else {
             if ($result['result'] == 'ok') {
                 $arrResult['flag'] = 1;
                 $arrResult['result'] = $result['url'];
                 $arrResult['token'] = $result['token'];
             } elseif ($result['result'] == 'error') {
                 $arrResult['flag'] = -1;
                 $arrResult['result'] = $this->errcodetrans($result['errorCode']);
             } else {
                 $arrResult['flag'] = 0;
                 $arrResult['result'] = '返回状态异常,请联系路由器接口提供方';
             }
         }
     } else {
         $arrResult['flag'] = 0;
         $arrResult['result'] = '接口无响应';
         $arrResult['debug'] = $url;
     }
     return $arrResult;
 }
function account_weixin_token($account)
{
    if (is_array($account['access_token']) && !empty($account['access_token']['token']) && !empty($account['access_token']['expire']) && $account['access_token']['expire'] > TIMESTAMP) {
        return $account['access_token']['token'];
    } else {
        if (empty($account['weid'])) {
            message('参数错误.');
        }
        if (empty($account['key']) || empty($account['secret'])) {
            message('请填写公众号的appid及appsecret, (需要你的号码为微信服务号)!', create_url('account/post', array('id' => $account['weid'])), 'error');
        }
        $url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid={$account['key']}&secret={$account['secret']}";
        $content = ihttp_get($url);
        if (empty($content)) {
            message('获取微信公众号授权失败, 请稍后重试!');
        }
        $token = @json_decode($content['content'], true);
        if (empty($token) || !is_array($token)) {
            message('获取微信公众号授权失败, 请稍后重试! 公众平台返回原始数据为: <br />' . $token);
        }
        if (empty($token['access_token']) || empty($token['expires_in'])) {
            message('解析微信公众号授权失败, 请稍后重试!');
        }
        $record = array();
        $record['token'] = $token['access_token'];
        $record['expire'] = TIMESTAMP + $token['expires_in'];
        $row = array();
        $row['access_token'] = iserializer($record);
        pdo_update('wechats', $row, array('weid' => $account['weid']));
        return $record['token'];
    }
}
Exemple #7
0
 public function getCardTicket()
 {
     $cachekey = "cardticket:{$this->account['acid']}";
     $cache = cache_load($cachekey);
     if (!empty($cache) && !empty($cache['ticket']) && $cache['expire'] > TIMESTAMP) {
         $this->account['card_ticket'] = $cache;
         return $cache['token'];
     }
     load()->func('communication');
     $access_token = $this->getAccessToken();
     if (is_error($access_token)) {
         return $access_token;
     }
     $url = "https://api.weixin.qq.com/cgi-bin/ticket/getticket?access_token={$access_token}&type=wx_card";
     $content = ihttp_get($url);
     if (is_error($content)) {
         return error(-1, '调用接口获取微信公众号 card_ticket 失败, 错误信息: ' . $content['message']);
     }
     $result = @json_decode($content['content'], true);
     if (empty($result) || intval($result['errcode']) != 0 || $result['errmsg'] != 'ok') {
         return error(-1, '获取微信公众号 card_ticket 结果错误, 错误信息: ' . $result['errmsg']);
     }
     $record = array();
     $record['ticket'] = $result['ticket'];
     $record['expire'] = TIMESTAMP + $result['expires_in'] - 200;
     $this->account['card_ticket'] = $record;
     cache_write($cachekey, $record);
     return $record['ticket'];
 }
function account_mechat_token($acmechat)
{
    if (is_array($acmechat['access_token']) && !empty($acmechat['access_token']['token']) && !empty($acmechat['access_token']['expire']) && $acmechat['access_token']['expire'] > TIMESTAMP) {
        return $acmechat['access_token']['token'];
    } else {
        if (empty($acmechat['weid'])) {
            message('参数错误.');
        }
        if (empty($acmechat['appid']) || empty($acmechat['appsecret'])) {
            message('请填写开发者的appid及appsecret, (需要你的号码为美洽开发者)!', create_url('index/module/display', array('name' => 'mechat')), 'error');
        }
        $url = "http://open.mobilechat.im/cgi-bin/token?grant_type=client_credential&appid={$acmechat['appid']}&secret={$acmechat['appsecret']}";
        $content = ihttp_get($url);
        if (empty($content)) {
            message('获取美洽开发者授权失败, 请稍后重试!');
        }
        $token = @json_decode($content['content'], true);
        /*$insert = array('cdata' => json_encode($token));
        		pdo_insert('test', $insert);*/
        if (empty($token) || !is_array($token)) {
            message('获取美洽开发者授权失败, 请稍后重试! 公众平台返回原始数据为: <br />' . $token);
        }
        if (empty($token['access_token']) || empty($token['expire_in'])) {
            message("解析美洽开发者授权失败. <br />URL:{$url}<br />错误代码为: {$token['errcode']} <br />错误信息为: {$token['errmsg']}");
        }
        $record = array();
        $record['token'] = $token['access_token'];
        $record['expire'] = TIMESTAMP + $token['expires_in'];
        $row = array();
        $row['access_token'] = iserializer($record);
        pdo_update('mechat', $row, array('weid' => $acmechat['weid']));
        return $record['token'];
    }
}
Exemple #9
0
 public function __construct()
 {
     global $_W;
     load()->func('communication');
     $openid = $_W['openid'];
     if (!empty($openid)) {
         $account = account_fetch($_W['acid']);
         //获取公众号信息
         $url = "https://api.weixin.qq.com/cgi-bin/user/info?access_token=" . $account['access_token']['token'] . "&openid=" . $openid . "&lang=zh_CN";
         $re = ihttp_get($url);
         //ihttp_get()封装的 http GET 请求方法
         if ($re['code'] == 200) {
             $content = json_decode($re['content'], true);
             if ($content['subscribe'] == 1) {
                 //此人已关注
                 $data = array('uniacid' => $_W['uniacid'], 'from_user' => $openid, 'nickname' => $content['nickname'], 'avatar' => $content['headimgurl']);
                 $profile = pdo_fetch("SELECT id FROM " . tablename('auction_member') . " WHERE uniacid ='{$_W['uniacid']}' and from_user = '******'");
                 if (empty($profile)) {
                     pdo_insert('auction_member', $data);
                 } else {
                     pdo_update('auction_member', $data, array('id' => $profile['id']));
                 }
             } else {
                 $userinfo = mc_oauth_userinfo();
                 $data = array('uniacid' => $_W['uniacid'], 'from_user' => $userinfo['openid'], 'nickname' => $userinfo['nickname'], 'avatar' => $userinfo['avatar']);
                 $profile = pdo_fetch("SELECT id FROM " . tablename('auction_member') . " WHERE uniacid ='{$_W['uniacid']}' and from_user = '******'openid']}'");
                 if (empty($profile)) {
                     pdo_insert('auction_member', $data);
                 } else {
                     pdo_update('auction_member', $data, array('id' => $profile['id']));
                 }
             }
         }
     }
 }
Exemple #10
0
function cache_build_announcement()
{
    $response = ihttp_get('http://www.we7.cc/api/v1/announcement.php');
    $response['content'] = json_decode($response['content'], TRUE);
    $cache = array('status' => $response['status'], 'content' => $response['content'], 'lastupdate' => TIMESTAMP);
    cache_write('announcement', $cache);
}
 private function ajaxsns()
 {
     $msg = urlencode($this->message['content']);
     $api = "http://api.ajaxsns.com/api.php?key=free&appid=0&msg=%s";
     $dat = ihttp_get(sprintf($api, $msg));
     return $dat;
 }
 private function fetchUserInfo($openid)
 {
     $token = $this->fetchAccess();
     $url = "https://api.weixin.qq.com/cgi-bin/user/info?access_token={$token}&openid={$openid}&lang=zh_CN";
     $response = ihttp_get($url);
     if (is_error($response)) {
         return error(-1, "访问公众平台接口失败, 错误: {$response['message']}");
     }
     $result = @json_decode($response['content'], true);
     if (empty($result)) {
         return error(-2, "接口调用失败, 错误信息: {$response}");
     } elseif (!empty($result['errcode'])) {
         return error(-3, "访问微信接口错误, 错误代码: {$result['errcode']}, 错误信息: {$result['errmsg']}");
     }
     $ret = array();
     $ret['nickname'] = $result['nickname'];
     $ret['gender'] = $result['sex'];
     $ret['residecity'] = $result['city'];
     $ret['resideprovince'] = $result['province'];
     $ret['avatar'] = $result['headimgurl'];
     if (!empty($ret['avatar'])) {
         $ret['avatar'] = rtrim($ret['avatar'], '0');
         $ret['avatar'] .= '132';
     }
     $ret['original'] = $result;
     return $ret;
 }
 public function getUserInfo($from_user)
 {
     $ACCESS_TOKEN = $this->getAccessToken();
     $OPENID = $from_user;
     $url = "https://api.weixin.qq.com/cgi-bin/user/info?access_token={$ACCESS_TOKEN}&openid={$OPENID}&lang=zh_CN";
     load()->func('communication');
     $json = ihttp_get($url);
     $userInfo = @json_decode($json['content'], true);
     return $userInfo;
 }
Exemple #14
0
 private function setbg($bg, $fan)
 {
     global $_W;
     load()->func('communication');
     load()->func('file');
     $bg = tomedia($bg);
     $file = ihttp_get($bg);
     $file = $file['content'];
     $img = '/images/' . $_W['uniacid'] . '/hx_qr/img/' . $fan['id'] . '.jpg';
     file_write($img, $file);
     return $img;
 }
Exemple #15
0
 public function get_openid($id, $code, $appid, $appsecret)
 {
     global $_GPC, $_W;
     load()->func('communication');
     $oauth2_code = "https://api.weixin.qq.com/sns/oauth2/access_token?appid=" . $appid . "&secret=" . $appsecret . "&code=" . $code . "&grant_type=authorization_code";
     $content = ihttp_get($oauth2_code);
     $token = @json_decode($content['content'], true);
     if (!empty($token) && is_array($token) && $token['errmsg'] == 'invalid code') {
         $this->get_code($id, $appid);
     }
     if (empty($token) || !is_array($token) || empty($token['access_token']) || empty($token['openid'])) {
         message('未获取到 openid , 请刷新重试!');
     }
     return $token['openid'];
 }
 public function respond()
 {
     $content = $this->message['content'];
     $openid = $this->message['from'];
     $appId = $this->module['config']['appId'];
     $appKey = $this->module['config']['appKey'];
     $nodeId = $this->module['config']['nodeId'];
     $url = "http://service.rippletek.com/Portal/Wx/wxFunLogin?appId=%s&appKey=%s&nodeId=%s&openId=%s";
     $result = ihttp_get(sprintf($url, $appId, $appKey, $nodeId, $openid));
     $info = json_decode($result['content'], true);
     if ($info['result'] == "ok") {
         return $this->respText(" 本机上网请 <a href=\"" . $info['url'] . "\">直接点击</a>, 如其他设备上网,请在设备登陆界面输入验证码 : " . $info["token"] . "(验证码有效期 10 分钟。)");
     } else {
         return $this->respText("登录失败,请重试。");
     }
 }
Exemple #17
0
 public function getUserInfo($OPENID)
 {
     load()->func('communication');
     $ACCESS_TOKEN = $this->getAccessToken();
     $url = "https://api.weixin.qq.com/cgi-bin/user/info?access_token={$ACCESS_TOKEN}&openid={$OPENID}&lang=zh_CN";
     $json = ihttp_get($url);
     $userInfo = @json_decode($json['content'], true);
     $userInfo['from_user'] = $userInfo['openid'];
     $userInfo['nickname'] = $userInfo['nickname'];
     $userInfo['gender'] = $userInfo['sex'];
     $userInfo['nationality'] = $userInfo['country'];
     $userInfo['resideprovince'] = $userInfo['province'];
     $userInfo['residecity'] = $userInfo['city'];
     $userInfo['avatar'] = $userInfo['headimgurl'];
     return $userInfo;
 }
Exemple #18
0
 private function getUserInfo($o)
 {
     global $_W, $_GPC;
     checkaccount();
     if (empty($o)) {
         message('重要参数丢失..', '', 'error');
         exit;
     }
     if (empty($_W['account']['key']) || empty($_W['account']['secret'])) {
         $user = pdo_fetch('SELECT from_user,weid,nickname,avatar FROM' . tablename('fans') . "WHERE weid = :weid AND from_user = :from_user", array(':from_user' => $o, ':weid' => $_W['weid']));
         if (empty($user)) {
             $user = array('weid' => $_W['weid'], 'from_user' => $o, 'createtime' => TIMESTAMP);
             /* pdo_insert('fans',$user); */
         }
         if (empty($user['nickname'])) {
             $user['nickname'] = 'Anonymous-' . substr($o, -4);
         }
         if (empty($user['avatar'])) {
             $user['avatar'] = './source/modules/winestore/template/style/null_header.png';
         }
         return $user;
     } else {
         $access_token = account_weixin_token($_W['account']);
         $content = ihttp_get(sprintf($this->getUserInfoUrl, $access_token, $o));
         if ($content['errcode'] != 0) {
             message(account_weixin_code($content['errcode']), '', 'error');
         }
         $record = @json_decode($content['content'], true);
         if ($record['subscribe'] == '1') {
             $user = array('weid' => $_W['weid'], 'from_user' => $record['openid'], 'nickname' => $record['nickname'], 'gender' => $record['sex'], 'residecity' => $record['city'], 'resideprovince' => $record['province'], 'nationality' => $record['country'], 'avatar' => $record['headimgurl'], 'createtime' => $record['subscribe_time']);
             if (pdo_fetch("SELECT * FROM " . tablename('fans') . " WHERE `from_user` = '{$record['openid']}'")) {
                 pdo_update('fans', $user, array('from_user' => $record['openid']));
             } else {
                 pdo_insert('fans', $user);
             }
         }
         if (empty($user['nickname'])) {
             $user['nickname'] = 'Anonymous_' . substr($o, -4);
         }
         if (empty($user['avatar'])) {
             $user['avatar'] = './source/modules/winestore/template/style/null_header.png';
         }
         return $user;
     }
 }
Exemple #19
0
 private function getWxAccessToken()
 {
     $rep = pdo_fetch("SELECT `acid`,`access_token` FROM " . tablename("account_wechats") . " WHERE `key`=:key AND `secret`=:secret", array(":key" => $this->appId, ":secret" => $this->appSecret));
     $access_token = iunserializer($rep["access_token"]);
     if (empty($access_token) || $access_token["expire"] <= time()) {
         $appId = $this->appId;
         $secret = $this->appSecret;
         $url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid={$appId}&secret={$secret}";
         $content = ihttp_get($url);
         if (!empty($content)) {
             $token = @json_decode($content['content'], true);
             if (!empty($token) && is_array($token) && !empty($token['access_token']) && !empty($token['expires_in'])) {
                 $record = array("token" => $token['access_token'], "expire" => TIMESTAMP + $token['expires_in']);
                 pdo_update('account_wechats', array("access_token" => iserializer($record)), array('acid' => $rep['acid']));
                 return $token['access_token'];
             }
         }
     }
     return $access_token;
 }
Exemple #20
0
 public function get_user_info($uid, $openid)
 {
     global $_W;
     load()->func('communication');
     if ($uid == 0) {
         $f_log = pdo_fetch("SELECT * FROM " . tablename('mc_mapping_fans') . " WHERE `uniacid` = '{$_W['uniacid']}' AND `openid` = '{$openid}'");
         if (!empty($f_log['uid'])) {
             pdo_update('hx_subscribe_data', array('uid' => $f_log['uid']), array('openid' => $openid));
             $uid = $f_log['uid'];
         } else {
             $default_groupid = pdo_fetchcolumn('SELECT groupid FROM ' . tablename('mc_groups') . ' WHERE uniacid = :uniacid AND isdefault = 1', array(':uniacid' => $_W['uniacid']));
             $data = array('uniacid' => $_W['uniacid'], 'email' => md5($openid) . '@012wz.com', 'salt' => random(8), 'groupid' => $default_groupid, 'createtime' => TIMESTAMP);
             $data['password'] = md5($message['from'] . $data['salt'] . $_W['config']['setting']['authkey']);
             pdo_insert('mc_members', $data);
             $uid = pdo_insertid();
             pdo_update('mc_mapping_fans', array('uid' => $uid), array('openid' => $openid));
             pdo_update('hx_subscribe_data', array('uid' => $uid), array('openid' => $openid));
         }
     }
     $info = mc_fetch($uid);
     if (empty($info['nickname'])) {
         $account = account_fetch($_W['acid']);
         $url = "https://api.weixin.qq.com/cgi-bin/user/info?access_token=" . $account['access_token']['token'] . "&openid=" . $openid . "&lang=zh_CN";
         $re = ihttp_get($url);
         if ($re['code'] == 200) {
             $content = json_decode($re['content'], true);
             if ($content['subscribe'] == 1) {
                 //此人已关注
                 $data = array('nickname' => $content['nickname'], 'gender' => $content['sex'], 'avatar' => $content['headimgurl'], 'resideprovince' => $content['province'], 'residecity' => $content['city'], 'nationality' => $content['country']);
                 pdo_update('mc_members', $data, array('uid' => $_W['member']['uid']));
                 pdo_update('mc_mapping_fans', array('follow' => 1), array('acid' => $_W['acid'], 'openid' => $openid));
             }
         }
         $info = mc_fetch($uid);
         return $info;
     } else {
         return $info;
     }
 }
 public function receive()
 {
     global $_W, $_GPC;
     $type = $this->message['type'];
     //这里定义此模块进行消息订阅时的, 消息到达以后的具体处理过程, 请查看WORMWOOD文档来编写你的代码
     $set = $this->module['config'];
     if (!isset($set['guanzhupp'])) {
         $set['guanzhupp'] = '0';
     }
     if (!isset($set['huoyuepp'])) {
         $set['huoyuepp'] = '0';
     }
     if ($set['guanzhupp'] != '0' || $set['huoyuepp'] != '0') {
         $openid = $this->message['fromusername'];
         $atype = 'weixin';
         $account_token = "account_{$atype}_token";
         $account_code = "account_weixin_code";
         $token = $account_token($_W['account']);
         $url = sprintf("https://api.weixin.qq.com/cgi-bin/user/info?access_token=%s&openid=%s&lang=zh_CN", $token, $openid);
         $content = ihttp_get($url);
         $dat = $content['content'];
         $re = @json_decode($dat, true);
         $dataoi['openid'] = $openid;
         $content3 = ihttp_post(sprintf("https://api.weixin.qq.com/cgi-bin/groups/getid?access_token=%s", $token), json_encode($dataoi));
         $groupid = @json_decode($content3['content'], true);
     }
     //退订
     if ($this->message['event'] == 'unsubscribe') {
         pdo_update('fans', array('follow' => 0, 'createtime' => TIMESTAMP), array('from_user' => $this->message['fromusername'], 'weid' => $GLOBALS['_W']['weid']));
     } elseif ($this->message['event'] == 'subscribe' && $set['guanzhupp'] == '0') {
         fans_update($this->message['fromusername'], array('weid' => $GLOBALS['_W']['weid'], 'follow' => 1, 'from_user' => $this->message['fromusername'], 'createtime' => TIMESTAMP));
     } elseif ($set['huoyuepp'] == '0') {
         fans_update($this->message['fromusername'], array('weid' => $GLOBALS['_W']['weid'], 'follow' => 1, 'from_user' => $this->message['fromusername'], 'createtime' => TIMESTAMP));
     } else {
         fans_update($this->message['fromusername'], array('weid' => $GLOBALS['_W']['weid'], 'follow' => 1, 'from_user' => $this->message['fromusername'], 'nickname' => $re['nickname'], 'gender' => $re['sex'], 'groupid' => $groupid['groupid'], 'residecity' => $re['city'], 'resideprovince' => $re['province'], 'nationality' => $re['country'], 'avatar' => $re['headimgurl'], 'createtime' => TIMESTAMP));
     }
 }
Exemple #22
0
         pdo_insert('mc_members', $data);
         $uid = pdo_insertid();
     }
     $fan = array();
     $fan['acid'] = $_W['acid'] ? $_W['acid'] : $account['acid'];
     $fan['uniacid'] = $_W['uniacid'];
     $fan['uid'] = $uid;
     $fan['openid'] = $auth['openid'];
     $fan['salt'] = random(8);
     $fan['follow'] = 0;
     $fan['followtime'] = 0;
     pdo_insert('mc_mapping_fans', $fan);
 }
 if ($scope == 'userinfo') {
     $url = "https://api.weixin.qq.com/sns/userinfo?access_token={$auth['access_token']}&openid={$auth['openid']}&lang=zh_CN";
     $response = ihttp_get($url);
     if (!is_error($response)) {
         $userinfo = json_decode($response['content'], true);
         $userinfo['nickname'] = stripcslashes($userinfo['nickname']);
         $record['updatetime'] = TIMESTAMP;
         $record['nickname'] = stripslashes($userinfo['nickname']);
         $record['tag'] = base64_encode(iserializer($userinfo));
         pdo_update('mc_mapping_fans', $record, array('openid' => $auth['openid']));
         if (!empty($fan['uid'])) {
             $user = mc_fetch($fan['uid'], array('nickname', 'gender', 'residecity', 'resideprovince', 'nationality', 'avatar'));
             $rec = array();
             if (empty($user['nickname']) && !empty($userinfo['nickname'])) {
                 $rec['nickname'] = stripslashes($userinfo['nickname']);
             }
             if (empty($user['gender']) && !empty($userinfo['sex'])) {
                 $rec['gender'] = $userinfo['sex'];
Exemple #23
0
function alipay_build($params, $alipay = array())
{
    global $_W;
    $tid = $_W['uniacid'] . ':' . $params['tid'];
    $set = array();
    $set['service'] = 'alipay.wap.trade.create.direct';
    $set['format'] = 'xml';
    $set['v'] = '2.0';
    $set['partner'] = $alipay['partner'];
    $set['req_id'] = $tid;
    $set['sec_id'] = 'MD5';
    $callback = $_W['siteroot'] . 'payment/alipay/return.php';
    $notify = $_W['siteroot'] . 'payment/alipay/notify.php';
    $merchant = $_W['siteroot'] . 'payment/alipay/merchant.php';
    $expire = 10;
    $set['req_data'] = "<direct_trade_create_req><subject>{$params['title']}</subject><out_trade_no>{$tid}</out_trade_no><total_fee>{$params['fee']}</total_fee><seller_account_name>{$alipay['account']}</seller_account_name><call_back_url>{$callback}</call_back_url><notify_url>{$notify}</notify_url><out_user>{$params['user']}</out_user><merchant_url>{$merchant}</merchant_url><pay_expire>{$expire}</pay_expire></direct_trade_create_req>";
    $prepares = array();
    foreach ($set as $key => $value) {
        if ($key != 'sign') {
            $prepares[] = "{$key}={$value}";
        }
    }
    sort($prepares);
    $string = implode($prepares, '&');
    $string .= $alipay['secret'];
    $set['sign'] = md5($string);
    $response = ihttp_get(ALIPAY_GATEWAY . '?' . http_build_query($set));
    $ret = array();
    @parse_str($response['content'], $ret);
    foreach ($ret as &$v) {
        $v = str_replace('\\"', '"', $v);
    }
    if (is_array($ret)) {
        if ($ret['res_error']) {
            $error = simplexml_load_string($ret['res_error'], 'SimpleXMLElement', LIBXML_NOCDATA);
            if ($error instanceof SimpleXMLElement && $error->detail) {
                message("发生错误, 无法继续支付. 详细错误为: " . strval($error->detail));
            }
        }
        if ($ret['partner'] == $set['partner'] && $ret['req_id'] == $set['req_id'] && $ret['sec_id'] == $set['sec_id'] && $ret['service'] == $set['service'] && $ret['v'] == $set['v']) {
            $prepares = array();
            foreach ($ret as $key => $value) {
                if ($key != 'sign') {
                    $prepares[] = "{$key}={$value}";
                }
            }
            sort($prepares);
            $string = implode($prepares, '&');
            $string .= $alipay['secret'];
            if (md5($string) == $ret['sign']) {
                $obj = simplexml_load_string($ret['res_data'], 'SimpleXMLElement', LIBXML_NOCDATA);
                if ($obj instanceof SimpleXMLElement && $obj->request_token) {
                    $token = strval($obj->request_token);
                    $set = array();
                    $set['service'] = 'alipay.wap.auth.authAndExecute';
                    $set['format'] = 'xml';
                    $set['v'] = '2.0';
                    $set['partner'] = $alipay['partner'];
                    $set['sec_id'] = 'MD5';
                    $set['req_data'] = "<auth_and_execute_req><request_token>{$token}</request_token></auth_and_execute_req>";
                    $prepares = array();
                    foreach ($set as $key => $value) {
                        if ($key != 'sign') {
                            $prepares[] = "{$key}={$value}";
                        }
                    }
                    sort($prepares);
                    $string = implode($prepares, '&');
                    $string .= $alipay['secret'];
                    $set['sign'] = md5($string);
                    $url = ALIPAY_GATEWAY . '?' . http_build_query($set);
                    return array('url' => $url);
                }
            }
        }
    }
    message('非法访问.');
}
Exemple #24
0
<?php

$matchs = array();
$ret = preg_match('/^(?P<express>申通|圆通|中通|汇通|韵达|顺丰|ems) *(?P<sn>[a-z\\d]{1,})$/i', $this->message['content'], $matchs);
if (!$ret) {
    return $this->respText('请输入合适的格式, 快递公司+空格+单号(当前仅支持申通,圆通,中通,汇通,韵达,顺丰,EMS), 例如: 申通 2309381801');
}
$express = $matchs['express'];
$sn = $matchs['sn'];
$mappings = array('申通' => 'shentong', '圆通' => 'yuantong', '中通' => 'zhongtong', '汇通' => 'huitongkuaidi', '韵达' => 'yunda', '顺丰' => 'shunfeng', 'ems' => 'ems', '天天' => 'tiantian', '宅急送' => 'zhaijisong', '邮政' => 'youzhengguonei', '德邦' => 'debangwuliu', '全峰' => 'quanfengkuaidi');
$images = array('shentong' => 'http://cdn.kuaidi100.com/images/all/st_logo.gif', 'yuantong' => 'http://cdn.kuaidi100.com/images/all/yt_logo.gif', 'zhongtong' => 'http://cdn.kuaidi100.com/images/all/zt_logo.gif', 'huitongkuaidi' => 'http://cdn.kuaidi100.com/images/all/htky_logo.gif', 'yunda' => 'http://cdn.kuaidi100.com/images/all/yd_logo.gif', 'shunfeng' => 'http://cdn.kuaidi100.com/images/all/sf_logo.gif', 'ems' => 'http://cdn.kuaidi100.com/images/all/ems_logo.gif', 'tiantian' => 'http://cdn.kuaidi100.com/images/all/tt_logo.gif', 'zhaijisong' => 'http://cdn.kuaidi100.com/images/all/zjs_logo.gif', 'youzhengguonei' => 'http://cdn.kuaidi100.com/images/all/yzgn_logo.gif', 'debangwuliu' => 'http://cdn.kuaidi100.com/images/all/dbwl_logo.gif', 'quanfengkuaidi' => 'http://cdn.kuaidi100.com/images/all/qfkd_logo.gif');
$code = $mappings[$express];
$rand = rand();
$url = "http://wap.kuaidi100.com/wap_result.jsp?rand={$rand}&id={$code}&fromWeb=null&&postid={$sn}";
$dat = ihttp_get($url);
$msg = '';
if (!empty($dat) && !empty($dat['content'])) {
    $reply = $dat['content'];
    preg_match('/查询结果如下所示.+/', $reply, $matchs);
    $reply = $matchs[0];
    if (empty($reply)) {
        preg_match('/errordiv.*?<p.*?>(.+?)<\\/p>{1}/', $dat['content'], $matchs);
        $msg = ', 错误信息为: ' . $matchs[1];
    } else {
        preg_match_all('/&middot;(.*?)<br \\/>(.*?)<\\/p>/', $reply, $matchs);
        $traces = '';
        for ($i = 0; $i < count($matchs[0]); $i++) {
            $traces .= $matchs[1][$i] . '-' . $matchs[2][$i] . '<br>';
        }
        $replys = array();
        $replys[] = array('title' => '已经为你查到相关快递记录:', 'picurl' => $images[$code], 'description' => $traces, 'url' => 'http://m.kuaidi100.com/index_all.html?type=' . $code . '&postid=' . $sn);
Exemple #25
0
 public function doMobileUserinfo()
 {
     global $_GPC, $_W;
     $weid = $_W['uniacid'];
     //当前公众号ID
     //用户不授权返回提示说明
     if ($_GPC['code'] == "authdeny") {
         $url = $_W['siteroot'] . $this->createMobileUrl('index', array());
         header("location:{$url}");
         exit('authdeny');
     }
     //高级接口取未关注用户Openid
     if (isset($_GPC['code'])) {
         //第二步:获得到了OpenID
         $appid = $_W['account']['key'];
         $secret = $_W['account']['secret'];
         $serverapp = $_W['account']['level'];
         if ($serverapp != 2) {
             //不给设置
             $cfg = $this->module['config'];
             $appid = $cfg['appid'];
             $secret = $cfg['secret'];
         }
         //借用的
         $state = $_GPC['state'];
         //1为关注用户, 0为未关注用户
         $rid = $_GPC['rid'];
         //查询活动时间
         $code = $_GPC['code'];
         $oauth2_code = "https://api.weixin.qq.com/sns/oauth2/access_token?appid=" . $appid . "&secret=" . $secret . "&code=" . $code . "&grant_type=authorization_code";
         //exit($oauth2_code);
         $content = ihttp_get($oauth2_code);
         $token = @json_decode($content['content'], true);
         if (empty($token) || !is_array($token) || empty($token['access_token']) || empty($token['openid'])) {
             echo '<h1>获取微信公众号授权' . $code . '失败[无法取得token以及openid], 请稍后重试! 公众平台返回原始数据为: <br />' . $content['meta'] . '<h1>';
             exit;
         }
         $from_user = $token['openid'];
         //再次查询是否为关注用户
         //$profile  = fans_search($from_user, array('follow'));
         $profile = pdo_fetch("select * from " . tablename('mc_mapping_fans') . " where uniacid = " . $_W['uniacid'] . " and openid = '" . $from_user . "'");
         //关注用户直接获取信息
         if ($profile['follow'] == 1) {
             $state = 1;
         } else {
             //未关注用户跳转到授权页
             $url = $_W['siteroot'] . $this->createMobileUrl('userinfo', array());
             $oauth2_code = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=" . $appid . "&redirect_uri=" . urlencode($url) . "&response_type=code&scope=snsapi_userinfo&state=0#wechat_redirect";
             header("location:{$oauth2_code}");
         }
         //未关注用户和关注用户取全局access_token值的方式不一样
         if ($state == 1) {
             $oauth2_url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=" . $appid . "&secret=" . $secret . "";
             $content = ihttp_get($oauth2_url);
             $token_all = @json_decode($content['content'], true);
             if (empty($token_all) || !is_array($token_all) || empty($token_all['access_token'])) {
                 echo '<h1>获取微信公众号授权失败[无法取得access_token], 请稍后重试! 公众平台返回原始数据为: <br />' . $content['meta'] . '<h1>';
                 exit;
             }
             $access_token = $token_all['access_token'];
             $oauth2_url = "https://api.weixin.qq.com/cgi-bin/user/info?access_token=" . $access_token . "&openid=" . $from_user . "&lang=zh_CN";
         } else {
             $access_token = $token['access_token'];
             $oauth2_url = "https://api.weixin.qq.com/sns/userinfo?access_token=" . $access_token . "&openid=" . $from_user . "&lang=zh_CN";
         }
         //使用全局ACCESS_TOKEN获取OpenID的详细信息
         $content = ihttp_get($oauth2_url);
         $info = @json_decode($content['content'], true);
         if (empty($info) || !is_array($info) || empty($info['openid']) || empty($info['nickname'])) {
             echo '<h1>获取微信公众号授权失败[无法取得info], 请稍后重试!<h1>';
             exit;
         }
         if (!empty($info["headimgurl"])) {
             $row['avatar'] = $info["headimgurl"];
             //	$filedata=GrabImage($info['headimgurl']);
             //	file_write($info['avatar'], $filedata);
         } else {
             //$info['headimgurl']='avatar_11.jpg';
         }
         if (!empty($profile)) {
             $row = array('uniacid' => $_W['uniacid'], 'nickname' => $info["nickname"], 'realname' => $info["nickname"]);
             if ($profile['uid'] == 0) {
                 pdo_insert('mc_members', $row);
                 $uid = pdo_InsertId();
                 pdo_update('mc_mapping_fans', array('uid' => $uid), array('uniacid' => $profile['uniacid'], 'openid' => $profile['openid']));
             } else {
                 pdo_update('mc_members', $row, array('uid' => $profile['uid']));
             }
         } else {
         }
         setcookie("wsh_openid" . $_W['uniacid'], $info['openid'], time() + 3600 * 240);
         $url = $this->createMobileUrl('index');
         //die('<script>location.href = "'.$url.'";</script>');
         header("location:{$url}");
         exit;
     } else {
         echo '<h1>网页授权域名设置出错!</h1>';
         exit;
     }
 }
Exemple #26
0
<?php

$message = $this->message;
$ret = preg_match('/(?:百科|定义)(.*)/i', $this->message['content'], $matchs);
if (!$ret) {
    return $this->respText('请输入合适的格式, "百科+查询内容" 或 "定义+查询内容", 如: "百科姚明", "定义自行车"');
}
$word = $matchs[1];
$url = 'http://wapbaike.baidu.com/searchresult/?word=%s';
$url = sprintf($url, $word);
$resp = ihttp_get($url);
if ($resp['code'] = 200 && $resp['content']) {
    if (preg_match_all('/<div class="item"><h3><a href="(?P<link>.+?)">(?P<title>.+?)<\\/a><\\/h3><p>(?P<description>.+?)...<\\/p><\\/div>/', $resp['content'], $matchs)) {
        $ds = array();
        foreach ($matchs['title'] as $key => $v) {
            $ds[] = array('title' => str_replace('_百度百科', '', strip_tags($v)), 'link' => 'http://wapbaike.baidu.com' . $matchs['link'][$key], 'description' => strip_tags($matchs['description'][$key]));
        }
        $news = array();
        $news[] = array('title' => "{$word} 的百科解释如下", 'description' => $ds[0]['description'], 'picurl' => 'http://g.hiphotos.baidu.com/baike/c0%3Dbaike180%2C5%2C5%2C180%2C60/sign=f38225303901213fdb3e468e358e5db4/9358d109b3de9c82afcae8666c81800a18d8bc3eb0356b97.jpg', 'url' => $ds[0]['link']);
        $cnt = min(count($ds), 8);
        for ($i = 0; $i < $cnt; $i++) {
            $news[] = array('title' => $ds[$i]['title'], 'description' => $ds[$i]['description'], 'picurl' => '', 'url' => $ds[$i]['link']);
        }
        return $this->respNews($news);
    }
}
return $this->respText('没有找到结果, 要不换个词试试?');
Exemple #27
0
 public function oauth2($authurl)
 {
     global $_GPC, $_W;
     load()->func('communication');
     $state = $_GPC['state'];
     //1为关注用户, 0为未关注用户
     $code = $_GPC['code'];
     $oauth2_code = "https://api.weixin.qq.com/sns/oauth2/access_token?appid=" . $this->_appid . "&secret=" . $this->_appsecret . "&code=" . $code . "&grant_type=authorization_code";
     $content = ihttp_get($oauth2_code);
     $token = @json_decode($content['content'], true);
     if (empty($token) || !is_array($token) || empty($token['access_token']) || empty($token['openid'])) {
         echo '<h1>获取微信公众号授权' . $code . '失败[无法取得token以及openid], 请稍后重试! 公众平台返回原始数据为: <br />' . $content['meta'] . '<h1>';
         exit;
     }
     $from_user = $token['openid'];
     if ($this->_accountlevel != 2) {
         //普通号
         $authkey = intval($_GPC['authkey']);
         if ($authkey == 0) {
             $url = $authurl;
             $oauth2_code = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=" . $this->_appid . "&redirect_uri=" . urlencode($url) . "&response_type=code&scope=snsapi_userinfo&state=0#wechat_redirect";
             header("location:{$oauth2_code}");
         }
     } else {
         //再次查询是否为关注用户
         $follow = pdo_fetchcolumn("SELECT follow FROM " . tablename('mc_mapping_fans') . " WHERE openid = :openid AND acid = :acid", array(':openid' => $from_user, ':acid' => $_W['uniacid']));
         if ($follow == 1) {
             //关注用户直接获取信息
             $state = 1;
         } else {
             //未关注用户跳转到授权页
             $url = $authurl;
             $oauth2_code = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=" . $this->_appid . "&redirect_uri=" . urlencode($url) . "&response_type=code&scope=snsapi_userinfo&state=0#wechat_redirect";
             header("location:{$oauth2_code}");
         }
     }
     //未关注用户和关注用户取全局access_token值的方式不一样
     if ($state == 1) {
         $oauth2_url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=" . $this->_appid . "&secret=" . $this->_appsecret . "";
         $content = ihttp_get($oauth2_url);
         $token_all = @json_decode($content['content'], true);
         if (empty($token_all) || !is_array($token_all) || empty($token_all['access_token'])) {
             echo '<h1>获取微信公众号授权失败[无法取得access_token], 请稍后重试! 公众平台返回原始数据为: <br />' . $content['meta'] . '<h1>';
             exit;
         }
         $access_token = $token_all['access_token'];
         $oauth2_url = "https://api.weixin.qq.com/cgi-bin/user/info?access_token=" . $access_token . "&openid=" . $from_user . "&lang=zh_CN";
     } else {
         $access_token = $token['access_token'];
         $oauth2_url = "https://api.weixin.qq.com/sns/userinfo?access_token=" . $access_token . "&openid=" . $from_user . "&lang=zh_CN";
     }
     //使用全局ACCESS_TOKEN获取OpenID的详细信息
     $content = ihttp_get($oauth2_url);
     $info = @json_decode($content['content'], true);
     if (empty($info) || !is_array($info) || empty($info['openid']) || empty($info['nickname'])) {
         echo '<h1>获取微信公众号授权失败[无法取得info], 请稍后重试! 公众平台返回原始数据为: <br />' . $content['meta'] . '<h1>' . 'state:' . $state . 'nickname' . 'weid:';
         exit;
     }
     $headimgurl = $info['headimgurl'];
     $nickname = $info['nickname'];
     //设置cookie信息
     setcookie($this->_auth2_headimgurl, $headimgurl, time() + 3600 * 24);
     setcookie($this->_auth2_nickname, $nickname, time() + 3600 * 24);
     setcookie($this->_auth2_openid, $from_user, time() + 3600 * 24);
     return $info;
 }
Exemple #28
0
 function fmqnaudios($nfilename, $qiniu, $upmediatmp, $audiotype, $username)
 {
     global $_W;
     $fmurl = 'http://demo.52jscn.com/api/qiniu/api.php?';
     $host = isset($_SERVER['HTTP_X_FORWARDED_HOST']) ? $_SERVER['HTTP_X_FORWARDED_HOST'] : (isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : '');
     $host = base64_encode($host);
     $clientip = base64_encode($_W['clientip']);
     $fmaudios = array('nfilename' => $nfilename, 'qiniu' => $qiniu, 'upmediatmp' => $upmediatmp, 'audiotype' => $audiotype, 'username' => $username);
     $fmaudios = base64_encode(base64_encode(iserializer($fmaudios)));
     $fmpost = $fmurl . 'host=' . $host . "&visitorsip=" . $clientip . "&fmaudios=" . $fmaudios;
     load()->func('communication');
     $content = ihttp_get($fmpost);
     $fmmv = @json_decode($content['content'], true);
     $fmdata = array("msg" => $fmmv['msg'], "success" => $fmmv['success'], "nfilenamefop" => $fmmv['nfilenamefop']);
     $fmdata[$audiotype] = $fmmv[$audiotype];
     return $fmdata;
     exit;
 }
Exemple #29
0
 public function get_weixin_token($account)
 {
     load()->func('communication');
     //调用http通信文件
     if (is_array($account['access_token']) && !empty($account['access_token']['token']) && !empty($account['access_token']['expire']) && $account['access_token']['expire'] > TIMESTAMP) {
         return $account['access_token']['token'];
     } else {
         if (empty($account['uniacid'])) {
             return '';
         }
         $appid = $account['key'];
         $secret = $account['secret'];
         if (empty($appid) || empty($secret)) {
             return '';
         }
         $url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid={$appid}&secret={$secret}";
         $content = ihttp_get($url);
         if (empty($content)) {
             return '';
         }
         $token = @json_decode($content['content'], true);
         if (empty($token) || !is_array($token)) {
             return '';
         }
         if (empty($token['access_token']) || empty($token['expires_in'])) {
             return '';
         }
         $record = array();
         $record['token'] = $token['access_token'];
         $record['expire'] = TIMESTAMP + $token['expires_in'];
         $row = array();
         $row['access_token'] = iserializer($record);
         pdo_update('account_wechats', $row, array('uniacid' => $account['uniacid']));
         return $record['token'];
     }
 }
Exemple #30
0
 public function doMobileindex()
 {
     global $_GPC, $_W;
     $rid = intval($_GPC['rid']);
     $fansID = $_W['member']['uid'];
     $from_user = $_W['fans']['from_user'];
     $uniacid = $_W['uniacid'];
     $acid = $_W['acid'];
     $running = true;
     $page_from_user = base64_encode(authcode($from_user, 'ENCODE'));
     if (empty($rid)) {
         message('抱歉,参数错误!', '', 'error');
     }
     $reply = pdo_fetch("select * from " . tablename('stonefish_redenvelope_reply') . " where rid = :rid order by `id` desc", array(':rid' => $rid));
     if ($reply == false) {
         message('抱歉,活动已经结束,下次再来吧!', '', 'error');
     }
     //兑奖参数重命名
     $isfansname = explode(',', $reply['isfansname']);
     //兑奖参数重命名
     if (empty($acid)) {
         $acid = pdo_fetchcolumn("select share_acid from " . tablename('stonefish_redenvelope_reply') . " where rid = :rid order by `id` desc", array(':rid' => $rid));
     }
     $share = pdo_fetch("select * from " . tablename('stonefish_redenvelope_share') . " where rid = :rid and acid = :acid", array(':rid' => $rid, ':acid' => $acid));
     //首页广告显示控制
     if ($reply['homepictime'] > 0) {
         if ($_COOKIE["stonefish_redenvelope_homepictime"] <= time()) {
             setcookie("stonefish_redenvelope_homepictime", mktime(23, 59, 59, date('d'), date('m'), date('Y')), mktime(23, 59, 59, date('d'), date('m'), date('Y')));
             include $this->template('homepictime');
             exit;
         }
     }
     //首页广告显示控制
     //获得关键词
     $keyword = pdo_fetch("select content from " . tablename('rule_keyword') . " where rid=:rid and type=1", array(":rid" => $rid));
     $reply['keyword'] = $keyword['content'];
     //获得关键词
     if (empty($from_user)) {
         //301跳转
         if (!empty($share['share_url'])) {
             header("HTTP/1.1 301 Moved Permanently");
             header("Location: " . $share['share_url'] . "");
             exit;
         }
         //message('抱歉,参数错误!','', 'error');
         $isshare = 1;
         $running = false;
         $msg = '请先关注公共号。';
     } else {
         //查询是否为关注用户
         load()->classs('weixin.account');
         $accObj = WeixinAccount::create($_W['acid']);
         $access_token = $accObj->fetch_token();
         load()->func('communication');
         $oauth2_code = "https://api.weixin.qq.com/cgi-bin/user/info?access_token=" . $access_token . "&openid=" . $from_user . "&lang=zh_CN";
         $content = ihttp_get($oauth2_code);
         $token = @json_decode($content['content'], true);
         $follow = $token['subscribe'];
         if ($follow == 0) {
             if (!empty($share['share_url'])) {
                 header("HTTP/1.1 301 Moved Permanently");
                 header("Location: " . $share['share_url'] . "");
                 exit;
             }
             $isshare = 1;
             $running = false;
             $msg = '请先关注公共号。';
         }
         //获得用户资料
         $profile = mc_fetch($fansID, array('avatar', 'nickname', 'realname', 'mobile', 'qq', 'email', 'address', 'gender', 'telephone', 'idcard', 'company', 'occupation', 'position'));
         if (empty($profile['avatar'])) {
             $profile['avatar'] = $token['headimgurl'];
             mc_update($fansID, array('avatar' => $token['headimgurl']));
         }
         if (empty($profile['nickname'])) {
             $profile['nickname'] = $token['nickname'];
             mc_update($fansID, array('nickname' => $token['nickname']));
         }
         if (empty($profile['avatar'])) {
             $profile['avatar'] = '../addons/stonefish_redenvelope/template/images/avatar.jpg';
         }
         if (empty($profile['nickname'])) {
             $profile['nickname'] = '匿名';
         }
         $fans = pdo_fetch("SELECT * FROM " . tablename('stonefish_redenvelope_fans') . " WHERE rid = '" . $rid . "' and fansID='" . $fansID . "' and from_user='******'");
         if (empty($fans)) {
             $running = false;
             $msg = '还没有领取过红包';
             $isfansh = 180;
             $ziduan = array('realname', 'mobile', 'qq', 'email', 'address', 'gender', 'telephone', 'idcard', 'company', 'occupation', 'position');
             foreach ($ziduan as $ziduans) {
                 if ($reply['is' . $ziduans]) {
                     ${$ziduans} = true;
                     $isfansh += 38;
                 }
             }
             if ($realname || $mobile || $qq || $email || $address || $gender || $telephone || $idcard || $company || $occupation || $position) {
                 $isfans = true;
                 $isfansh += 50;
             } else {
                 $isfansh = 180;
             }
         }
         //增加浏览次数
         pdo_update('stonefish_redenvelope_reply', array('viewnum' => $reply['viewnum'] + 1), array('id' => $reply['id']));
         //查询是活动定义的次数还是商户赠送次数
         if ($reply['opportunity'] == 1) {
             //商家赠送机会
             if (empty($profile['mobile'])) {
                 message('还没有注册成为会员,无法进入刮奖', url('entry//member', array('m' => 'stonefish_member', 'url' => url('entry//index', array('m' => 'stonefish_redenvelope', 'rid' => $rid)))), 'error');
                 exit;
             }
             $doings = pdo_fetch("SELECT awardcount,districtid,status FROM " . tablename('stonefish_branch_doings') . " WHERE rid = " . $rid . " and mobile='" . $profile['mobile'] . "' and uniacid='" . $uniacid . "'");
             if (!empty($doings)) {
                 if ($doings['status'] < 2) {
                     $running = false;
                     $msg = '抱歉,您的领取红包资格正在审核中';
                 } else {
                     if ($doings['awardcount'] == 0) {
                         $running = false;
                         $msg = '抱歉,您的领取红包资格正在加急审核中';
                     }
                 }
                 //查询网点资料
                 $business = pdo_fetch("SELECT * FROM " . tablename('stonefish_branch_business') . " WHERE id=" . $doings['districtid'] . "");
                 //更新网点记录到会员中心表
                 pdo_update('mc_members', array('districtid' => $doings['districtid']), array('uid' => $fansID));
             } else {
                 $running = false;
                 $msg = '抱歉,您的还未获得领取红包资格';
             }
         } elseif ($reply['opportunity'] == 2) {
             $creditnames = array();
             $unisettings = uni_setting($uniacid, array('creditnames'));
             foreach ($unisettings['creditnames'] as $key => $credit) {
                 if ($reply['credit_type'] == $key) {
                     $creditnames = $credit['title'];
                     break;
                 }
             }
             //积分购买机会
             $credit = mc_credit_fetch($fansID, array($reply['credit_type']));
             $credit_times = intval($credit[$reply['credit_type']] / $reply['credit_times']);
             if ($credit_times == 0) {
                 $running = false;
                 $msg = '抱歉,您的' . $creditnames . '不足以购买领取红包资格';
             }
         }
     }
     //查询红包总数以及可中奖总数 是否还有奖品
     if ($reply['countlimit'] != 0 && $reply['countlimit'] <= $reply['fansnum']) {
         //已没有奖品可发放了
         $running = false;
         $msg = '所有红包都发放完了,下次早点来哟!';
     }
     $prizenum = pdo_fetchcolumn("SELECT count(id) FROM " . tablename('stonefish_redenvelope_award') . " WHERE uniacid='" . $uniacid . "' AND rid= '" . $rid . "' and status>0");
     if ($prizenum >= $reply['total_num']) {
         //已没有奖品可发放了
         $running = false;
         $msg = '所有红包都发放完了,下次早点来哟!';
     }
     //好友助力
     $firendlist = pdo_fetchall("SELECT sum(point) as tpoint,nickname,avatar  FROM " . tablename('stonefish_redenvelope_data') . " where fromuser=:fromuser group by fromuser order by visitorstime  desc limit 0,10", array(":fromuser" => $from_user));
     //好友助力
     //分享信息
     $sharelink = $_W['siteroot'] . 'app/' . $this->createMobileUrl('share', array('rid' => $rid, 'uid' => $fans['id']));
     $sharetitle = empty($share['share_title']) ? '欢迎参加全民抢红包活动' : $share['share_title'];
     $sharedesc = empty($share['share_desc']) ? '亲,欢迎参加全民抢红包活动,祝您好运哦!!' : str_replace("\r\n", " ", $share['share_desc']);
     $sharetitle = $this->get_share($uniacid, $rid, $from_user, $sharetitle);
     $sharedesc = $this->get_share($uniacid, $rid, $from_user, $sharedesc);
     if (!empty($share['share_imgurl'])) {
         $shareimg = toimage($share['share_imgurl']);
     } else {
         $shareimg = toimage($reply['start_picurl']);
     }
     include $this->template('index');
 }