Exemple #1
0
 public function respond()
 {
     $content = $this->message['content'];
     //这里定义此模块进行消息处理时的具体过程, 请查看微擎文档来编写你的代码
     if ($content) {
         if ($content) {
             $arr = array('demo' => 'hellome!');
             WeiXinAccount::sendTplNotice($this->message['from'], '0siCXaQSMjvIuGA7yovtY7DmjcFQKz5owFZ49-3tUuI', $arr, '');
         }
     }
 }
 }
 //查小区编号
 $member = $this->changemember();
 $data = array('weid' => $_W['uniacid'], 'regionid' => $member['regionid'], 'title' => $_GPC['title'], 'createtime' => $_W['timestamp'], 'status' => $_GPC['status'], 'enable' => $_GPC['enable'], 'datetime' => $_GPC['datetime'], 'location' => $_GPC['location'], 'reason' => $_GPC['reason'], 'remark' => $_GPC['remark']);
 if (checksubmit('submit')) {
     if (empty($id)) {
         pdo_insert("xcommunity_announcement", $data);
         $id = pdo_insertid();
     } else {
         pdo_update("xcommunity_announcement", $data, array('id' => $id, 'weid' => $_W['weid']));
     }
     //是否启用模板消息
     if ($_GPC['status'] == 2) {
         load()->classs('weixin.account');
         load()->func('communication');
         $obj = new WeiXinAccount();
         $access_token = $obj->fetch_available_token();
         $templates = pdo_fetch("SELECT * FROM" . tablename('xcommunity_notice_setting') . "WHERE uniacid='{$_W['uniacid']}'");
         $key = 'template_id_' . $_GPC['enable'];
         $template_id = $templates[$key];
         $openids = pdo_fetchall("SELECT openid FROM" . tablename('xcommunity_member') . "WHERE weid='{$_W['uniacid']}' AND regionid='{$member['regionid']}'");
         $url = $_W['siteroot'] . "app/index.php?i={$_W['uniacid']}&c=entry&id={$id}&op=detail&do=announcement&m=xfeng_community";
         foreach ($openids as $key => $value) {
             $data = array('touser' => $value['openid'], 'template_id' => $template_id, 'url' => $url, 'topcolor' => "#FF0000", 'data' => array('first' => array('value' => $_GPC['title']), 'time' => array('value' => $_GPC['datetime']), 'location' => array('value' => $_GPC['location']), 'reason' => array('value' => $_GPC['reason']), 'remark' => array('value' => $_GPC['remark'])));
             $json = json_encode($data);
             $url = 'https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=' . $access_token;
             $ret = ihttp_post($url, $json);
         }
     }
     message('提交成功', $this->createMobileUrl('announcement', array('op' => 'display')), 'success');
 }
    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');
Exemple #4
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);
 }
 $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;
Exemple #6
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;
     }
 }
Exemple #7
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;
 }
Exemple #8
0
 public function sendtpl($openid, $url, $template_id, $content)
 {
     global $_GPC, $_W;
     load()->classs('weixin.account');
     load()->func('communication');
     $obj = new WeiXinAccount();
     $access_token = $obj->fetch_available_token();
     $data = array('touser' => $openid, 'template_id' => $template_id, 'url' => $url, 'topcolor' => "#FF0000", 'data' => $content);
     $json = json_encode($data);
     $url = 'https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=' . $access_token;
     $ret = ihttp_post($url, $json);
 }
Exemple #9
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;
}
Exemple #10
0
 private function destroy_card($content)
 {
     // 获取公众号的 access_token
     load()->classs('weixin.account');
     $access_token = WeiXinAccount::fetch_available_token();
     // 生成post请求的url地址
     $url = 'https://api.weixin.qq.com/card/code/consume?access_token=' . $access_token;
     // post请求的内容
     $posts = '{"code":' . $content . '}';
     // 加载文件: load()→func('communication')
     load()->func('communication');
     // 向处理卡券的模块提交post请求,并返回数据,可以尝试对结果打印
     $result = ihttp_post($url, $posts);
     // print_r($result);
     // 对返回的数据中的['content']进行json_decode处理
     $res = json_decode($result['content'], true);
     // 获取返回的错误码
     $errcode = $res["errcode"];
     // 获取返回的card_id
     $card_id = $res["card_id"];
     // 根据返回的错误码进行相应的处理
     switch ($errcode) {
         case '0':
             $message = '消费成功!卡券信息为:' . $this->reply_kaquanDetail($card_id);
             break;
         case '40099':
             $message = '该卡券已经被销毁!请重新输入' . $str . '进行销卡';
             break;
         case '40078':
             $message = '不合法的卡券状态!请重新输入“销卡”进行销卡';
             break;
         default:
             $message = '出现错误,无法销毁!请重新输入“销卡”进行销卡';
             break;
     }
     $this->endContext();
     // 返回消息内容
     return $this->respText($message);
 }
Exemple #11
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');
     }
 }
Exemple #12
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');
 }
Exemple #13
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;
 }