コード例 #1
0
ファイル: site.php プロジェクト: alextiannus/wormwood_wechat
 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;
     }
 }
コード例 #2
0
ファイル: site.php プロジェクト: alextiannus/wormwood_wechat
 private function changeWechatSend($id, $status, $msg = '')
 {
     global $_W;
     $paylog = pdo_fetch("SELECT plid, openid, tag FROM " . tablename('paylog') . " WHERE tid = '{$id}' AND status = 1 AND type = 'wechat'");
     if (!empty($paylog['openid'])) {
         $paylog['tag'] = iunserializer($paylog['tag']);
         $send = array('appid' => $_W['account']['payment']['wechat']['appid'], 'openid' => $paylog['openid'], 'transid' => $paylog['tag']['transaction_id'], 'out_trade_no' => $paylog['plid'], 'deliver_timestamp' => TIMESTAMP, 'deliver_status' => $status, 'deliver_msg' => $msg);
         $sign = $send;
         $sign['appkey'] = $_W['account']['payment']['wechat']['signkey'];
         ksort($sign);
         foreach ($sign as $key => $v) {
             $key = strtolower($key);
             $string .= "{$key}={$v}&";
         }
         $send['app_signature'] = sha1(rtrim($string, '&'));
         $send['sign_method'] = 'sha1';
         $token = account_weixin_token($_W['account']);
         $sendapi = 'https://api.weixin.qq.com/pay/delivernotify?access_token=' . $token;
         $response = ihttp_request($sendapi, json_encode($send));
         $response = json_decode($response['content'], true);
         if (empty($response)) {
             message('发货失败,请检查您的公众号权限或是公众号AppId和公众号AppSecret!');
         }
         if (!empty($response['errcode'])) {
             message($response['errmsg']);
         }
     }
 }
コード例 #3
0
$dos = array('display', 'upload');
$do = in_array($do, $dos) ? $do : 'display';
$t = $_GPC['t'];
if ($do == 'display') {
    $pindex = max(1, intval($_GPC['page']));
    $psize = 10;
    $types = empty($_GPC['types']) ? array() : $_GPC['types'];
    if (!empty($types)) {
        $condition = array();
        $where = '';
        foreach ($types as $type) {
            $condition[] = " type='{$type}' ";
        }
        $where = " AND (" . implode('OR', $condition) . ") ";
    }
}
if ($foo == 'upload') {
    if (checksubmit()) {
        $type = $_GPC['type'];
        $media = array('filename' => $_FILES['media']['name'], 'filelength' => $_FILES['media']['size'], 'content-type' => $_FILES['media']['type']);
        $contentTypes = array('jpeg', 'audio/mp3', 'video/mpeg4');
        $token = account_weixin_token($_W['account']);
        $url = "http://file.api.weixin.qq.com/cgi-bin/media/upload?access_token={$token}&type={$type}";
        $extra = array();
        $response = ihttp_request($url, $media, $extra);
        exit;
        $first = array('type' => $type, 'media' => $_FILES['media']['name']);
        message('上传成功.');
    }
}
template('platform/resource');
コード例 #4
0
 public function barCodeCreateFixed($barcode)
 {
     unset($barcode['expire_seconds']);
     if (empty($barcode['action_info']['scene']['scene_id']) || empty($barcode['action_name'])) {
         return error('1', 'Invalid params');
     }
     $token = account_weixin_token($this->account);
     $url = sprintf($this->apis['barcode']['post'], $token);
     $response = ihttp_request($url, json_encode($barcode));
     if (is_error($response)) {
         return $response;
     }
     $content = @json_decode($response['content'], true);
     if (empty($content)) {
         return error('1', 'Interface communication failed');
     }
     if (!empty($content['errcode'])) {
         return error($content['errcode'], $content['errmsg']);
     }
     return $content;
 }
コード例 #5
0
ファイル: site.php プロジェクト: alextiannus/wormwood_wechat
 public function doMobileshareuserview()
 {
     global $_GPC, $_W;
     $weid = $_W['weid'];
     //当前公众号ID
     $rid = $_GPC['rid'];
     $from_user = $_W['fans']['from_user'];
     $page_from_user = base64_encode(authcode($from_user, 'ENCODE'));
     $fromuser = authcode(base64_decode($_GPC['fromuser']), 'DECODE');
     $page_fromuser = $_GPC['fromuser'];
     $serverapp = $_W['account']['level'];
     //是否为高级号
     $cfg = $this->module['config'];
     $appid = $cfg['appid'];
     $secret = $cfg['secret'];
     if (isset($_COOKIE["user_oauth2_avatar"]) && isset($_COOKIE["user_oauth2_nickname"]) && isset($_COOKIE["user_oauth2_openid"])) {
         $grabgiftsviewurl = $_W['siteroot'] . $this->createMobileUrl('shareuserdata', array('rid' => $rid, 'fromuser' => $page_fromuser));
         header("location:{$grabgiftsviewurl}");
         exit;
     } else {
         if (!empty($from_user)) {
             //取得openid后查询是否为高级号
             if ($serverapp == 2) {
                 //高级号查询是否关注
                 $profile = fans_search($from_user, array('follow'));
                 if ($profile['follow'] == 2) {
                     //已关注直接获取信息
                     $access_token = account_weixin_token($_W['account']);
                     $oauth2_url = "https://api.weixin.qq.com/cgi-bin/user/info?access_token=" . $access_token . "&openid=" . $from_user . "&lang=zh_CN";
                     $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>';
                         exit;
                     } else {
                         $avatar = $info['headimgurl'];
                         $nickname = $info['nickname'];
                         //设置cookie信息
                         setcookie("user_oauth2_avatar", $avatar, time() + 3600 * 24 * 7);
                         setcookie("user_oauth2_nickname", $nickname, time() + 3600 * 24 * 7);
                         setcookie("user_oauth2_openid", $from_user, time() + 3600 * 24 * 7);
                         $grabgiftsviewurl = $_W['siteroot'] . $this->createMobileUrl('shareuserdata', array('rid' => $rid, 'fromuser' => $page_fromuser));
                         header("location:{$grabgiftsviewurl}");
                         exit;
                     }
                 } else {
                     //非关注直接跳转授权页
                     $appid = $_W['account']['key'];
                     $url = $_W['siteroot'] . $this->createMobileUrl('oauth2', array('rid' => $rid, 'fromuser' => $page_fromuser));
                     $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}");
                     exit;
                 }
             } else {
                 //普通号直接跳转授权页
                 if (!empty($appid)) {
                     //有借用跳转授权页没有则跳转普通注册页
                     $url = $_W['siteroot'] . $this->createMobileUrl('oauth2', array('rid' => $rid, 'fromuser' => $page_fromuser));
                     $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}");
                     exit;
                 } else {
                     $reguser = $_W['siteroot'] . $this->createMobileUrl('reguser', array('rid' => $rid));
                     header("location:{$reguser}");
                     exit;
                 }
             }
         } else {
             //取不到openid 直接跳转授权页
             if (!empty($appid)) {
                 //有借用跳转授权页没有则跳转普通
                 $url = $_W['siteroot'] . $this->createMobileUrl('oauth2', array('rid' => $rid, 'fromuser' => $page_fromuser));
                 $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}");
                 exit;
             } else {
                 $reguser = $_W['siteroot'] . $this->createMobileUrl('reguser', array('rid' => $rid));
                 header("location:{$reguser}");
                 exit;
             }
         }
     }
 }
コード例 #6
0
ファイル: site.php プロジェクト: keycoolkui/weixinfenxiao
 public function doMobileUserinfo()
 {
     global $_W, $_GPC;
     $weid = $_W['uniacid'];
     //当前公众号ID
     $id = $_GPC['id'];
     //用户不授权返回提示说明
     if ($_GPC['code'] == "authdeny") {
         $url = $_W['siteroot'] . "app/" . $this->createMobileUrl('index', array('id' => $id));
         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 != 4) {
             $cfg = $this->module['config'];
             $appid = $cfg['appid'];
             $secret = $cfg['secret'];
             if (empty($appid) || empty($secret)) {
                 return;
             }
         }
         $state = $_GPC['state'];
         //1为关注用户, 0为未关注用户
         //查询活动时间
         $code = $_GPC['code'];
         $oauth2_code = "https://api.weixin.qq.com/sns/oauth2/access_token?appid=" . $appid . "&secret=" . $secret . "&code=" . $code . "&grant_type=authorization_code";
         load()->func('communication');
         $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 = pdo_fetch("select follow from " . tablename('mc_mapping_fans') . " where openid=:openid limit 1", array(":openid" => $from_user));
         //关注用户直接获取信息
         if ($profile['follow'] == 1) {
             $state = 1;
         } else {
             //未关注用户跳转到授权页
             $url = $_W['siteroot'] . "app/" . $this->createMobileUrl('userinfo', array('id' => $id));
             $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 && $serverapp != 4) {
             $access_token = account_weixin_token($_W['account']);
             $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"])) {
             $info['avatar'] = 'avatar/' . $info["openid"] . '.jpg';
         } else {
             $info['headimgurl'] = 'avatar_11.jpg';
         }
         $oauth_openid = "hl_bug5" . $_W['uniacid'];
         setcookie($oauth_openid, iserializer($info), time() + 3600 * 240);
         $url = $this->createMobileUrl('index', array('id' => $id));
         //die('<script>location.href = "'.$url.'";</script>');
         header("location:{$url}");
         exit;
     } else {
         echo '<h1>网页授权域名设置出错!</h1>';
         exit;
     }
 }
コード例 #7
0
ファイル: site.php プロジェクト: alextiannus/wormwood_wechat
 private function wechatText($msg, $o)
 {
     global $_GPC, $_W;
     $token = account_weixin_token($_W['account']);
     if (empty($token)) {
         $token = account_weixin_token($_W['account']);
     }
     if (empty($msg)) {
         message('诶呦,厉害啦..消息还能为空了?');
     }
     if (empty($o)) {
         message('诶呦,厉害啦..发送对象还能为空了?');
     }
     $sendurl = "https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token=%s";
     $url = sprintf($sendurl, $token);
     $dat = urldecode(json_encode(array('touser' => $o, 'msgtype' => 'text', 'text' => array('content' => urlencode($msg)))));
     $data = ihttp_post($url, $dat);
     if ($data['code'] != 200) {
         message('网络不畅..请稍后再尝试...');
     }
     $content = json_decode($data['content'], true);
     if ($content['errcode'] != 0) {
         message(account_weixin_code($content['errcode']));
         exit;
     } else {
         return 'ok';
     }
 }