public function getHengdaUsers()
 {
     $date = new DateTime();
     $date_start = Input::get('start', '');
     $date_end = Input::get('end', '');
     if ($date_start) {
         $date_start = strtotime($date_start);
     }
     if ($date_end) {
         $date_end = strtotime($date_end);
     }
     try {
         $wecht = new WechatApi('hengda');
         $re = $wecht->getFollowUser();
         $re = $wecht->getUsers($re['data']['openid']);
         $data = [];
         foreach ($re as $key => $user) {
             $check = true;
             if ($date_start && $user['subscribe_time'] < $date_start) {
                 $check = false;
             }
             if ($date_end && $user['subscribe_time'] > $date_end) {
                 $check = false;
             }
             if ($check) {
                 $data[] = $user;
             }
         }
         $re = Tools::reTrue('获取恒大微信用户成功', $data);
     } catch (Exception $e) {
         $re = Tools::reFalse($e->getCode(), '获取恒大微信用户失败:' . $e->getMessage());
     }
     return Response::json($re);
 }
Example #2
0
 public function getSgin($share_conf)
 {
     import('WechatApi');
     $tokenObj = new WechatApi(array('appid' => $this->appid, 'appsecret' => $this->appsecret));
     $access_token = $tokenObj->get_access_token();
     file_put_contents('token.txt', $access_token);
     $ticket = $this->getTicket($access_token['access_token']);
     $url = "http://" . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
     $sign_data = $this->addSign($ticket, $url);
     $share_html = $this->createHtml($sign_data, $share_conf);
     return $share_html;
 }
Example #3
0
function isSub($openid)
{
    import('WechatApi');
    $tokenObj = new WechatApi(array('appid' => option('config.wechat_appid'), 'appsecret' => option('config.wechat_appsecret')));
    $access_token = $tokenObj->get_access_token();
    $url = 'https://api.weixin.qq.com/cgi-bin/user/info?openid=' . $openid . '&access_token=' . $access_token['access_token'];
    $classData = json_decode(Http::curlGet($url));
    if ($classData->subscribe == 0) {
        //没有关注
        return 0;
    } else {
        return 1;
    }
}
Example #4
0
    $modules[$i]['author'] = 'gy.wang';
    /* 网址 */
    $modules[$i]['website'] = '';
    /* 版本号 */
    $modules[$i]['version'] = '0.1.0';
    /* 配置信息 */
    $modules[$i]['config'] = array(array('name' => 'lead_days', 'type' => 'text', 'value' => '1'));
    return;
}
$lead_days = intval($cron['lead_days']);
$lead_days = $lead_days > 0 ?: 1;
// 计算到期时间点
$add_day_str = "+{$lead_days} days";
$t = strtotime($add_day_str);
$date = date('Y-m-d', $t);
$time = strtotime($date . ' 23:59:59');
$begin = strtotime($date);
$sql = "SELECT b.user_id, sum(b.amount) AS amount, count(b.bonus_id) as cnt, u.wxid FROM " . $ecs->table('user_bonus', b) . ", wxch_user AS u " . " WHERE b.user_id = u.uid AND b.order_id = 0 AND b.expire_time >= {$begin} AND b.expire_time < {$time} + 1" . " GROUP BY b.user_id ";
$query = $db->query($sql);
$link = $_CFG['site_url'] . '/mobile/user.php?act=bonus';
$tmplid = 'n3Pmjdmez5JmaEUCAHEHujfj8BgqMXNkO5FGfAhHACM';
$param = array('first' => array('color' => '#000000'), 'keynote1' => array('color' => '#000000'), 'keynote2' => array('color' => '#000000'), "remark" => array('color' => '#0000ff', 'value' => "\n点击查看我的优惠券。\n如有任何问题可致电客服咨询:{$_CFG[service_phone]}"));
include_once ROOT_PATH . '/includes/cls_wechat.php';
$wechat = new WechatApi();
while ($rs = $db->fetch_array($query)) {
    //if ($rs['user_id'] != 1) continue;
    $param['first']['value'] = "您有{$rs[cnt]}张优惠券明天即将过期,请在过期前使用。";
    $param['keynote1']['value'] = "共计{$rs[amount]}元优惠券";
    $param['keynote2']['value'] = date('Y年n月j日', $time);
    $result = $wechat->send_template_msg($rs['wxid'], $tmplid, $param, $link);
}
Example #5
0
    /* 代码 */
    $modules[$i]['code'] = basename(__FILE__, '.php');
    /* 描述对应的语言项 */
    $modules[$i]['desc'] = 'update_wx_users_desc';
    /* 作者 */
    $modules[$i]['author'] = 'gy.wang';
    /* 网址 */
    $modules[$i]['website'] = '';
    /* 版本号 */
    $modules[$i]['version'] = '0.1.0';
    /* 配置信息 */
    $modules[$i]['config'] = array();
    return;
}
set_time_limit(0);
require_once ROOT_PATH . 'includes/cls_wechat.php';
$wechat = new WechatApi();
// 检查是否存在昵称和头像
$rs = $db->getAll("SELECT uid, wxid FROM wxch_user");
foreach ($rs as &$user) {
    $wx_user = $wechat->get_user_info($user['wxid']);
    if (!empty($wx_user)) {
        if ($wx_user['subscribe'] == 1) {
            $data = array('subscribe' => 1, 'nickname' => $wx_user['nickname'], 'sex' => $wx_user['sex'], 'city' => $wx_user['city'], 'country' => $wx_user['country'], 'province' => $wx_user['province'], 'language' => $wx_user['language'], 'headimgurl' => $wx_user['headimgurl'], 'subscribe_time' => $wx_user['subscribe_time'], 'dateline' => time());
        } else {
            $data = array('subscribe' => $wx_user['subscribe'] > 0 ? 2 : 0, 'dateline' => time());
        }
        // 更新微信用户数据
        $db->autoExecute('wxch_user', $data, 'UPDATE', 'uid = ' . $user['uid']);
    }
}
Example #6
0
    $modules[$i]['version'] = '0.1.0';
    /* 配置信息 */
    $modules[$i]['config'] = array(array('name' => 'mind_sql', 'type' => 'textarea', 'value' => 'SELECT u.user_id, w.wxid FROM ecs_users u, wxch_user w WHERE
    u.user_id = w.uid AND u.mobile_phone IS NOT NULL AND w.subscribe = 1
    AND NOT EXISTS (SELECT 1 FROM ecs_user_bonus b WHERE u.user_id = b.user_id AND b.order_id = 0 AND b.expire_time < unix_timestamp())
    AND NOT EXISTS (SELECT 1 FROM ecs_order_info o WHERE u.user_id = o.user_id AND o.add_time > unix_timestamp() - 864000)'), array('name' => 'give_bonus_id', 'type' => 'text', 'value' => ''), array('name' => 'notice_message', 'type' => 'textarea', 'value' => ''));
    return;
}
$now = time();
$sql = "SELECT * FROM " . $ecs->table('bonus_type') . " WHERE send_type = 0 AND type_id = " . intval($cron['give_bonus_id']);
$bonus = $db->getRow($sql);
if (!empty($bonus) && $bonus['send_start_date'] <= $now && $bonus['send_end_date'] > $now) {
    $expire_time = get_expire_time($bonus);
    $ub = array('bonus_type_id' => $bonus['type_id'], 'amount' => $bonus['type_money'], 'add_time' => $now, 'expire_time' => $expire_time);
    include_once ROOT_PATH . '/includes/cls_wechat.php';
    $wechat = new WechatApi();
    $href = $_CFG['site_url'] . '/mobile/';
    $tmplid = 'FRYrwOR7gxcvFGU3a1_RIv87GamInBnW_3CrENj-sa0';
    $message = array('first' => array('color' => '#0000ff', 'value' => "您已获得一张{$bonus[type_money]}元水果优惠券。\n{$cron[notice_message]}"), 'keyword1' => array('color' => '#000000', 'value' => $bonus['type_name']), 'keyword2' => array('color' => '#000000', 'value' => '最鲜蜂水果订购'), 'keyword3' => array('color' => '#000000', 'value' => date('Y-m-d', $expire_time)), 'keyword4' => array('color' => '#000000', 'value' => '结算付款时选择优惠券即可使用'), "remark" => array('color' => '#000000', 'value' => "如有任何问题可致电客服咨询:{$_CFG[service_phone]}"));
    $query = $db->query($cron['mind_sql']);
    while ($rs = $db->fetch_array($query)) {
        $ub['user_id'] = $rs['user_id'];
        $db->autoExecute($ecs->table('user_bonus'), $ub);
        $wechat->send_template_msg($rs['wxid'], $tmplid, $message, $href);
    }
}
function get_expire_time($bonus)
{
    if (!empty($bonus['use_time_limit'])) {
        $expire_time = min(time() + intval($bonus['use_time_limit']), $bonus['use_end_date']);
    } else {
Example #7
0
     /* 根据会员ID取得手机号和openid */
     $sql = "SELECT u.user_id, u.mobile_phone, u.user_name, w.wxid FROM " . $ecs->table('users', 'u') . " LEFT JOIN wxch_user w ON u.user_id = w.uid " . " WHERE u.user_id " . db_create_in($id_array);
     $user_list = $db->getAll($sql);
     $count = count($user_list);
 }
 /* 发送红包 */
 $loop = 0;
 $now = time();
 $bonus_type = bonus_type_info($_REQUEST['id']);
 check_bonus_type($bonus_type);
 //$tpl = get_mail_template('send_bonus');
 //$today = local_date($_CFG['date_format']);
 $expire_time = min($bonus_type['use_end_date'], $now + $bonus_type['use_time_limit']);
 //模板消息配置
 include_once ROOT_PATH . '/includes/cls_wechat.php';
 $wechat = new WechatApi();
 $href = $_CFG['site_url'] . '/mobile/user.php?act=bonus';
 $tmplid = 'FRYrwOR7gxcvFGU3a1_RIv87GamInBnW_3CrENj-sa0';
 $param = array('first' => array('color' => '#000000', 'value' => '您有一张优惠券已到账'), 'keyword1' => array('color' => '#000000', 'value' => $bonus_type['type_name']), 'keyword2' => array('color' => '#000000', 'value' => '客服发放'), 'keyword3' => array('color' => '#000000', 'value' => date('Y-m-d H:i', $expire_time)), 'keyword4' => array('color' => '#000000', 'value' => '订单满' . $bonus_type['min_goods_amount'] . '元可用'), "remark" => array('color' => '#0000ff', 'value' => "点击查看详情"));
 foreach ($user_list as $key => $val) {
     $sql = "INSERT INTO " . $ecs->table('user_bonus') . " (bonus_type_id, bonus_sn, user_id, used_time, order_id, emailed,amount,add_time,expire_time) " . "VALUES ('{$_REQUEST['id']}', 0, '{$val['user_id']}', 0, 0, " . BONUS_NOT_SMS . ",{$bonus_type['type_money']},{$now},{$expire_time})";
     $db->query($sql);
     //发送微信模板消息通知
     if (!empty($val['wxid'])) {
         $wechat->send_template_msg($val['wxid'], $tmplid, $param, $href);
     }
     if ($loop >= $limit) {
         break;
     } else {
         $loop++;
     }
Example #8
0
 private function _getOpenReplay($responseId)
 {
     $post_string = $GLOBALS["HTTP_RAW_POST_DATA"];
     $openReplayInfo = OpenReplayModel::model()->with('open_openPlatForm')->findByPk($responseId);
     $apiUrl = $openReplayInfo->open_openPlatForm->apiUrl;
     $token = $openReplayInfo->open_openPlatForm->token;
     $wechatApi = new WechatApi($token);
     $url = $wechatApi->buildSignUrl($apiUrl);
     $result = HttpRequest::sendHttpRequest($url, $post_string, 'POST', array("Content-type: text/xml"));
     return $result['content'] ? $result['content'] : '';
 }
Example #9
0
/**
 * 创建推广代理
 * @param int $user_id
 */
function create_promotion_agent($user_id)
{
    global $ecs, $db;
    // 查询可用的微信二维码
    $sql = "SELECT id FROM " . $ecs->table('weixin_qrcode') . " WHERE in_use = 0 ORDER BY id ASC";
    $qrcode = $db->getOne($sql);
    if (empty($qrcode)) {
        $db->autoExecute($ecs->table('weixin_qrcode'), array('type' => 1, 'purpose' => 1, 'in_use' => 1));
        $qrcode = $db->insert_id();
        // 通过微信接口创建
        include_once ROOT_PATH . '/includes/cls_wechat.php';
        $wechat = new WechatApi();
        $wx_qr = $wechat->create_permanent_qrcode(WechatApi::QRCODE_SCENE_LIMIT, $qrcode);
        $db->autoExecute($ecs->table('weixin_qrcode'), array('ticket' => $wx_qr['ticket'], 'content' => $wx_qr['url']), 'UPDATE', "id = {$qrcode}");
    } else {
        $db->autoExecute($ecs->table('weixin_qrcode'), array('purpose' => 1, 'in_use' => 1), 'UPDATE', "id = {$qrcode}");
    }
    $db->autoExecute($ecs->table('promotion_agent'), array('user_id' => $user_id, 'wx_qrcode' => $qrcode));
}
Example #10
0
/**
 * ECSHOP 程序说明
 * ===========================================================
 * * 版权所有 2014-2016 南京蜂蚁网络科技有限公司,并保留所有权利。
 * 网站地址: http://www.bestbeefresh.com;
 * ----------------------------------------------------------
 * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和
 * 使用;不允许对程序代码以任何形式任何目的的再发布。
 * ==========================================================
 */
define('IN_ECS', true);
require './init.php';
require ROOT_PATH . 'includes/cls_wechat.php';
require ROOT_PATH . 'api/wechat/event.php';
$wechat_api = new WechatApi();
// 检查签名
if (!$wechat_api->checkSignature($_REQUEST['signature'], $_REQUEST['timestamp'], $_REQUEST['nonce'])) {
    exit;
}
$echostr = $_REQUEST['echostr'];
if ($_SERVER['REQUEST_METHOD'] == 'GET') {
    echo $echostr;
    exit;
}
// Read Post data
$raw = file_get_contents('php://input');
!empty($raw) || die('Invalid Input');
$data = new SimpleXMLElement($raw);
$input = array();
foreach ($data as $key => $value) {
Example #11
0
 /**
  * 转接平台状态检查
  * @param $id
  */
 public function actionOpenStatus($id)
 {
     $result = 0;
     $model = OpenPlatformModel::model()->findByPk($id);
     if ($model) {
         $echostr = 'hello';
         $wechatApi = new WechatApi($model->token);
         $url = $wechatApi->buildSignUrl($model->apiUrl, array('echostr' => $echostr));
         $content = HttpRequest::sendHttpRequest($url);
         if ($content['content'] == $echostr) {
             $result = 1;
         }
         $model->status = $result;
         $model->save();
     }
     echo json_encode(array('result' => $result));
 }
Example #12
0
 public function get_tmp_qrcode($qrcode_id)
 {
     $appid = option('config.wechat_appid');
     $appsecret = option('config.wechat_appsecret');
     if (empty($appid) || empty($appsecret)) {
         return array('error_code' => 1, 'msg' => '请联系管理员配置【AppId】【 AppSecret】');
     }
     import('Http');
     $http = new Http();
     //微信授权获得access_token
     import('WechatApi');
     $tokenObj = new WechatApi(array('appid' => $appid, 'appsecret' => $appsecret));
     $access_token = $tokenObj->get_access_token();
     $qrcode_url = 'https://api.weixin.qq.com/cgi-bin/qrcode/create?access_token=' . $access_token['access_token'];
     $post_data['expire_seconds'] = 604800;
     $post_data['action_name'] = 'QR_SCENE';
     $post_data['action_info']['scene']['scene_id'] = $qrcode_id;
     $json = $http->curlPost($qrcode_url, json_encode($post_data));
     if (!$json['errcode']) {
         return array('error_code' => 0, 'id' => $qrcode_id, 'ticket' => 'https://mp.weixin.qq.com/cgi-bin/showqrcode?ticket=' . urlencode($json['ticket']));
     } else {
         return array('error_code' => 1, 'msg' => '产生二维码发生错误。发生错误:错误代码 ' . $json['errcode'] . ',微信返回错误信息:' . $json['errmsg']);
     }
 }