Beispiel #1
0
 /**
  * 发送消息
  * 
  * @param unknown $send            
  */
 private function send_text_message($to_user_openid, $content)
 {
     global $_W;
     $send = array('msgtype' => 'text', 'touser' => $to_user_openid, 'text' => array('content' => urlencode($content)));
     load()->classs('weixin.account');
     $account = WeiXinAccount::create($_W['account']['acid']);
     return $account->sendCustomNotice($send);
 }
Beispiel #2
0
    exit;
}
$_W['account']['groupid'] = $_W['uniaccount']['groupid'];
$_W['account']['qrcode'] = "{$_W['attachurl']}qrcode_{$_W['acid']}.jpg?time={$_W['timestamp']}";
$_W['account']['avatar'] = "{$_W['attachurl']}headimg_{$_W['acid']}.jpg?time={$_W['timestamp']}";
if ($_W['container'] == 'wechat') {
    $jsauth_acc = $_W['account'];
    if ($jsauth_acc['level'] < 3) {
        load()->model('account');
        $unisetting = uni_setting();
        $acid = intval($unisetting['jsauth_acid']);
        if (!empty($acid) && $acid != $_W['acid']) {
            $account = account_fetch($acid);
            if (!empty($account)) {
                $jsauth_acc = $account;
            }
            unset($account);
        }
        unset($acid, $unisetting);
    }
    load()->classs('weixin.account');
    $accObj = WeiXinAccount::create($jsauth_acc);
    $_W['account']['jssdkconfig'] = $accObj->getJssdkConfig();
    $_W['account']['jsauth_acid'] = $jsauth_acc['acid'];
    unset($jsauth_acc, $accObj);
}
$_W['card_permission'] = 0;
if ($_W['acid'] && $_W['account']['level'] >= 3 && $_W['container'] == 'wechat') {
    $_W['card_permission'] = 1;
}
load()->func('compat.biz');
Beispiel #3
0
 private function sendMobilePayMsg($order, $goods, $paytype, $ordergoods)
 {
     global $_W, $_GPC;
     $address = pdo_fetch("SELECT * FROM " . tablename('wwx_fxxt_address') . " WHERE id = :id", array(':id' => $order['addressid']));
     //查询收货地址
     $cfg = $this->module['config'];
     //获取模块设置信息
     $template_id = $cfg['msgtmp']['neworder'];
     if (!empty($template_id)) {
         $from_user = $order['from_user'];
         $tokens = $this->get_weixin_token();
         ///6.解析微信公众号授权token
         if (empty($tokens)) {
             return;
         }
         //模板消息
         $template = array('first' => array('value' => "订单已创建成功,请关注“{$_W['account']['name']}”,点击进入查看订单状态。", 'color' => "#743A3A"), 'keyword1' => array('title' => '时间', 'value' => date('Y-m-d H:i:s', $order['createtime']), 'color' => '#4a5077'), 'keyword2' => array('title' => '订单号', 'value' => $order['ordersn'], 'color' => '#4a5077'), 'keyword3' => array('title' => '支付方式', 'value' => $paytype, 'color' => '#4a5077'), 'remark' => array('value' => '订单生成成功,请到后台查看!', 'color' => '#4a5077'));
         $url = $_W['siteroot'] . "app/" . $this->createMobileUrl('myorder', array('orderid' => $order['id'], 'op' => 'detail'));
         load()->classs('weixin.account');
         $accObj = WeiXinAccount::create($_W['account']);
         $res = $accObj->sendTplNotice($from_user, $template_id, $template, $url, '#7B68EE');
         if (!empty($cfg['msgtmp']['openid'])) {
             $openids = explode(',', $cfg['msgtmp']['openid']);
             foreach ($openids as $openidsend) {
                 if (empty($openidsend)) {
                     continue;
                 }
                 $accObj->sendTplNotice($openidsend, $template_id, $template, '', '#7B68EE');
             }
         }
         return true;
     }
 }
 $oauth = @json_decode($response['content'], true);
 if (is_array($oauth) && !empty($oauth['openid'])) {
     $_SESSION['oauth_openid'] = $oauth['openid'];
     $_SESSION['oauth_acid'] = $_W['oauth_account']['acid'];
     if (intval($_W['account']['level']) == 4) {
         $fan = mc_fansinfo($oauth['openid']);
         if (!empty($fan)) {
             $_SESSION['openid'] = $oauth['openid'];
             if (!empty($fan['uid'])) {
                 $member = mc_fetch($fan['uid'], array('uid'));
                 if (!empty($member) && $member['uniacid'] == $_W['uniacid']) {
                     $_SESSION['uid'] = $member['uid'];
                 }
             }
         } else {
             $accObj = WeiXinAccount::create($_W['account']);
             $userinfo = $accObj->fansQueryInfo($oauth['openid']);
             //if(!is_error($userinfo) && !empty($userinfo) && is_array($userinfo) && !empty($userinfo['subscribe'])) {
             if (!is_error($userinfo) && !empty($userinfo) && is_array($userinfo)) {
                 $userinfo['nickname'] = stripcslashes($userinfo['nickname']);
                 $userinfo['avatar'] = $userinfo['headimgurl'];
                 unset($userinfo['headimgurl']);
                 $_SESSION['userinfo'] = base64_encode(iserializer($userinfo));
                 $record = array('openid' => $userinfo['openid'], 'uid' => 0, 'acid' => $_W['acid'], 'uniacid' => $_W['uniacid'], 'salt' => random(8), 'updatetime' => TIMESTAMP, 'nickname' => stripslashes($userinfo['nickname']), 'follow' => $userinfo['subscribe'], 'followtime' => $userinfo['subscribe_time'], 'unfollowtime' => 0, 'tag' => base64_encode(iserializer($userinfo)));
                 if (!isset($setting['passport']) || empty($setting['passport']['focusreg'])) {
                     $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($oauth['openid']) . '@cstrong.cn', 'salt' => random(8), 'groupid' => $default_groupid, 'createtime' => TIMESTAMP, 'password' => md5($message['from'] . $data['salt'] . $_W['config']['setting']['authkey']), 'nickname' => stripslashes($userinfo['nickname']), 'avatar' => rtrim($userinfo['avatar'], '0') . 132, 'gender' => $userinfo['sex'], 'nationality' => $userinfo['country'], 'resideprovince' => $userinfo['province'] . '省', 'residecity' => $userinfo['city'] . '市');
                     pdo_insert('mc_members', $data);
                     $uid = pdo_insertid();
                     $record['uid'] = $uid;
                     $_SESSION['uid'] = $uid;
Beispiel #5
0
 public function checkMember($openid = '')
 {
     global $_W;
     $acc = WeiXinAccount::create($_W['acid']);
     $userinfo = $acc->fansQueryInfo($openid);
     load()->model('mc');
     $uid = mc_openid2uid($openid);
     pdo_update('mc_members', array('nickname' => $userinfo['nickname'], 'gender' => $userinfo['sex'], 'nationality' => $userinfo['country'], 'resideprovince' => $userinfo['province'], 'residecity' => $userinfo['city'], 'avatar' => $userinfo['headimgurl']), array('uid' => $uid));
     pdo_update('mc_mapping_fans', array('nickname' => $userinfo['nickname']), array('uniacid' => $_W['uniacid'], 'openid' => $openid));
     $model = m('member');
     $member = $model->getMember($openid);
     if (empty($member)) {
         $mc = mc_fetch($uid, array('realname', 'nickname', 'mobile', 'avatar', 'resideprovince', 'residecity', 'residedist'));
         $member = array('uniacid' => $_W['uniacid'], 'uid' => $uid, 'openid' => $openid, 'realname' => $mc['realname'], 'mobile' => $mc['mobile'], 'nickname' => $mc['nickname'], 'avatar' => $mc['avatar'], 'gender' => $mc['gender'], 'province' => $mc['residecity'], 'city' => $mc['residecity'], 'area' => $mc['resizedist'], 'createtime' => time(), 'status' => 0);
         pdo_insert('ewei_shop_member', $member);
         $member['id'] = pdo_insertid();
         $member['isnew'] = true;
     } else {
         $member['nickname'] = $userinfo['nickname'];
         $member['avatar'] = $userinfo['headimgurl'];
         $member['province'] = $userinfo['province'];
         $member['city'] = $userinfo['city'];
         pdo_update('ewei_shop_member', $member, array('id' => $member['id']));
         $member['isnew'] = false;
     }
     return $member;
 }
Beispiel #6
0
function mc_oauth_userinfo($acid = 0)
{
    global $_W;
    if (isset($_SESSION['userinfo'])) {
        $userinfo = unserialize(base64_decode($_SESSION['userinfo']));
        return $userinfo;
    }
    if ($_W['container'] != 'wechat') {
        return array();
    }
    if (!empty($_SESSION['openid']) && intval($_W['account']['level']) >= 3) {
        $accObj = WeiXinAccount::create($_W['account']);
        $userinfo = $accObj->fansQueryInfo($_SESSION['openid']);
        if (!is_error($userinfo) && !empty($userinfo) && is_array($userinfo) && !empty($userinfo['nickname'])) {
            $userinfo['nickname'] = stripcslashes($userinfo['nickname']);
            $userinfo['avatar'] = $userinfo['headimgurl'];
            unset($userinfo['headimgurl']);
            $_SESSION['userinfo'] = base64_encode(iserializer($userinfo));
            $fan = mc_fansinfo($_SESSION['openid']);
            if (!empty($fan)) {
                $record = array('updatetime' => TIMESTAMP, 'nickname' => stripslashes($userinfo['nickname']), 'follow' => $userinfo['subscribe'], 'followtime' => $userinfo['subscribe_time'], 'tag' => base64_encode(iserializer($userinfo)));
                pdo_update('mc_mapping_fans', $record, array('openid' => $_SESSION['openid'], 'acid' => $_W['acid'], 'uniacid' => $_W['uniacid']));
            }
            if (!empty($fan['uid']) || !empty($_SESSION['uid'])) {
                $uid = intval($fan['uid']);
                if (empty($uid)) {
                    $uid = intval($_SESSION['uid']);
                }
                $member = mc_fetch($uid, array('nickname', 'gender', 'residecity', 'resideprovince', 'nationality', 'avatar'));
                $record = array();
                if (empty($member['nickname']) && !empty($userinfo['nickname'])) {
                    $record['nickname'] = stripslashes($userinfo['nickname']);
                }
                if (empty($member['gender']) && !empty($userinfo['sex'])) {
                    $record['gender'] = $userinfo['sex'];
                }
                if (empty($member['residecity']) && !empty($userinfo['city'])) {
                    $record['residecity'] = $userinfo['city'] . '市';
                }
                if (empty($member['resideprovince']) && !empty($userinfo['province'])) {
                    $record['resideprovince'] = $userinfo['province'] . '省';
                }
                if (empty($member['nationality']) && !empty($userinfo['country'])) {
                    $record['nationality'] = $userinfo['country'];
                }
                if (empty($member['avatar']) && !empty($userinfo['avatar'])) {
                    $record['avatar'] = rtrim($userinfo['avatar'], '0') . 132;
                }
                if (!empty($record)) {
                    pdo_update('mc_members', $record, array('uid' => intval($uid)));
                }
            }
            return $userinfo;
        }
    }
    if (empty($_W['oauth_account'])) {
        return error(-1, '未指定网页授权公众号, 无法获取用户信息.');
    }
    if (empty($_W['oauth_account']['key']) || empty($_W['oauth_account']['secret'])) {
        return error(-2, '公众号未设置 appId 或 secret.');
    }
    if (intval($_W['oauth_account']['level']) < 4) {
        return error(-3, '公众号非认证服务号, 无法获取用户信息.');
    }
    $state = 'we7sid-' . $_W['session_id'];
    $_SESSION['dest_url'] = base64_encode($_SERVER['QUERY_STRING']);
    $url = $_W['siteroot'] . "app/index.php?i={$_W['uniacid']}&j={$_W['acid']}&c=auth&a=oauth&scope=userinfo";
    $callback = urlencode($url);
    $forward = 'https://open.weixin.qq.com/connect/oauth2/authorize?appid=' . $_W['oauth_account']['key'] . '&redirect_uri=' . $callback . '&response_type=code&scope=snsapi_userinfo&state=' . $state . '#wechat_redirect';
    header('Location: ' . $forward);
    exit;
}
Beispiel #7
0
 public function doWebTemplate()
 {
     global $_W, $_GPC;
     $ops = array('display', 'edit', 'delete');
     // 只支持此 3 种操作.
     $op = in_array($_GPC['op'], $ops) ? $_GPC['op'] : 'display';
     load()->classs('weixin.account');
     $appid = $this->module['config']['appid'];
     $appsecrect = $this->module['config']['appsecrect'];
     $uniacid = $this->uniacid;
     $sql = "SELECT * FROM " . tablename($this->account_wechats) . " WHERE `uniacid`=:uniacid AND `key`=:key AND `secret`=:secret LIMIT 1";
     $params = array(':uniacid' => $uniacid, ':key' => $appid, ':secret' => $appsecrect);
     $result = pdo_fetch($sql, $params);
     if ($result == null) {
         message('请将微赞公众号设置里的appid和appsecrect填写完整!', '', 'error');
     }
     $account = WeiXinAccount::create($result['acid']);
     if ($op == 'display') {
         $data = $this->module['config'];
         $r = $account->fetchFansGroups();
         $group = $r['groups'];
         load()->func('tpl');
         include $this->template('template_send');
     }
     if ($op == 'edit') {
         if (checksubmit()) {
             $data = $_GPC['data']['key'];
             // 获取打包值
             $gro = $_GPC['data']['group'];
             $keys = $this->module['config']['key'];
             $colors = $this->module['config']['color'];
             $postdata = array();
             for ($i = 0; $i < count($data); $i++) {
                 $postdata[$keys[$i]] = array('value' => $data[$i], 'color' => $colors[$i]);
             }
             $tpl_id_short = $this->module['config']['tpl_id_short'];
             $url = $this->module['config']['url'];
             $topcolor = $this->module['config']['topcolor'];
             $result = $account->fansAll();
             $fans = $result['fans'];
             if ($gro == -1) {
                 $t = 0;
                 for ($i = 0; $i < $result['total']; $i++) {
                     $t++;
                     $touser = $fans[$i];
                     $account->sendTplNotice($touser, $tpl_id_short, $postdata, $url, $topcolor);
                 }
             } else {
                 $t = 0;
                 for ($i = 0; $i < $result['total']; $i++) {
                     $touser = $fans[$i];
                     $r = $account->fetchFansGroupid($touser);
                     if ($r['groupid'] == $gro) {
                         $t++;
                         $account->sendTplNotice($touser, $tpl_id_short, $postdata, $url, $topcolor);
                     }
                 }
             }
             message("发送成功!共发送至" . $t . "人!", '', 'success');
             // 保存成功
         }
         $r = $account->fetchFansGroups();
         $group = $r['groups'];
         load()->func('tpl');
         include $this->template('template_send');
     }
 }
Beispiel #8
0
 public function doMobileDetail()
 {
     global $_GPC, $_W;
     $id = $_GPC['id'];
     $fromuser = $_W['fans']['from_user'];
     $inputinfo = pdo_fetch("SELECT name,tel FROM " . tablename($this->listtable) . " WHERE sid = :sid and fromuser=:fromuser", array(':sid' => $id, ':fromuser' => $fromuser));
     if (!$inputinfo) {
         $reginfo = fans_search($fromuser, array('realname', 'mobile'));
     } else {
         $reginfo = array();
         $reginfo['realname'] = $inputinfo['name'];
         $reginfo['mobile'] = $inputinfo['tel'];
     }
     $item = pdo_fetch("SELECT * FROM " . tablename($this->headtable) . " WHERE id = :id", array(':id' => $id));
     if (empty($item)) {
         message('该喜帖已经删除', '', 'error');
     }
     $hslists = unserialize($item['hs_pic']);
     if (is_array($hslists)) {
         //兼容0.5数据
         foreach ($hslists as &$h) {
             if (is_array($h) && isset($h['attachment'])) {
                 $h = $h['attachment'];
             }
         }
         unset($h);
     }
     // 分享
     load()->classs('weixin.account');
     $accObj = WeiXinAccount::create($_W['acid']);
     $jssdkconfig = $accObj->getJssdkConfig();
     unset($accObj);
     include $this->template('detail');
 }
Beispiel #9
0
 public function createWexinAccount()
 {
     global $_W;
     load()->classs('weixin.account');
     $acid = $_W['account']['acid'];
     $uniacid = $_W['uniacid'];
     $account = null;
     if (!empty($acid) && $acid != $uniacid) {
         $account = WeiXinAccount::create($_W['account']['acid']);
     }
     if (empty($account)) {
         $account = WeiXinAccount::create($_W['uniacid']);
     }
     return $account;
 }