Пример #1
0
 public function template($filename, $flag = TEMPLATE_INCLUDEPATH)
 {
     global $_W, $_GPC;
     $_W['template'] = $_W['account']['template'];
     $_W['template']['source'] = $_W['account']['template'];
     $source = IA_ROOT . "/addons/quicktemplate/{$this->mn}/{$_W['template']}/{$filename}.html";
     $compile = IA_ROOT . "/data/tpl/app/{$_W['template']}/{$this->mn}/{$filename}.tpl.php";
     if (!empty($_GPC['__template'])) {
         $source = IA_ROOT . "/addons/quicktemplate/{$this->mn}/{$_GPC['__template']}/{$filename}.html";
         if (!is_file($source)) {
             die('invalid debug template ' . $_GPC['__template']);
         }
     }
     if (!is_file($source)) {
         $source = IA_ROOT . "/addons/{$this->mn}/template/mobile/{$filename}.html";
         if (!is_file($source)) {
             $source = "{$_W['template']['source']}/mobile/default/{$this->mn}/{$filename}.html";
             if (!is_file($source)) {
                 $source = "{$_W['template']['source']}/mobile/{$_W['account']['template']}/{$filename}.html";
                 if (!is_file($source)) {
                     $source = "{$_W['template']['source']}/mobile/default/{$filename}.html";
                     if (!is_file($source)) {
                         exit("Error: template source '{$filename}' is not exist!");
                     }
                 }
             }
         }
     }
     WeUtility::logging('compile source', array($source, $compile));
     if (DEVELOPMENT || !is_file($compile) || filemtime($source) > filemtime($compile)) {
         template_compile($source, $compile, true);
     }
     return $compile;
 }
Пример #2
0
	public function start() {
		if(empty($this->token)) {
			exit('Access Denied');
		}
		if(!WeUtility::checkSign($this->token)) {;
			exit('Access Denied');
		}
		if(strtolower($_SERVER['REQUEST_METHOD']) == 'get') {
			exit($_GET['echostr']);
		}
		if(strtolower($_SERVER['REQUEST_METHOD']) == 'post') {
			$postStr = $GLOBALS["HTTP_RAW_POST_DATA"];
			$this->message = WeUtility::parse($postStr);
			if (empty($this->message)) {
				WeUtility::logging('waring', 'Request Failed');
				exit('Request Failed');
			}
			WeUtility::logging('trace', $this->message);
			$this->before();
			$this->response = $this->matcher();
			$this->response['content'] = $this->process();
			if(empty($this->response['content']) || ($this->response['content']['type'] == 'text' && empty($this->response['content']['content'])) || ($this->response['content']['type'] == 'news' && empty($this->response['content']['items']))) {
				$this->response['module'] = 'default';
				$this->response['content'] = $this->process();
			}
			$this->after();
			WeUtility::logging('response', $this->response);
			exit(WeUtility::response($this->response['content']));
		}
		WeUtility::logging('waring', 'Request Failed');
		exit('Request Failed');
	}
Пример #3
0
 private function fans_search($user, $fields = array())
 {
     global $_W;
     $fields_str = self::$select_fields;
     $sql = "SELECT {$fields_str} FROM " . tablename(self::$t_sys_fans) . " a, " . tablename(self::$t_sys_member) . " b WHERE a.openid = :openid AND a.uniacid= :uniacid AND a.uid = b.uid";
     $fans = pdo_fetch($sql, array(':openid' => $user, ':uniacid' => $_W['uniacid']));
     WeUtility::logging('sql', $fans);
     return $fans;
 }
Пример #4
0
 private function tryLink()
 {
     global $_GPC, $_W, $_COOKIE;
     yload()->classs('quick_link', 'translink');
     $_link = new TransLink();
     WeUtility::logging("shareby", array('GPC' => $_GPC['shareby'], 'cookie' => $_COOKIE['shareby' . $_W['weid']], 'fans' => $_W['fans']['from_user']));
     if ($_GPC['shareby'] != $_W['fans']['from_user']) {
         $_link->link($_W['weid'], $_W['fans']);
     }
 }
Пример #5
0
 public function receive()
 {
     if ($this->message['msgtype'] == 'event') {
         if ($this->message['event'] == 'subscribe' && !empty($this->message['ticket'])) {
             $scene_id = $this->message['eventkey'];
             WeUtility::logging("Receiver:SUBSCRIBE", $scene_id);
         } elseif ($this->message['event'] == 'SCAN') {
             $scene_id = $this->message['eventkey'];
             WeUtility::logging("Receiver:SCAN", $scene_id);
         }
     }
 }
Пример #6
0
 private function refreshUserInfo($from_user)
 {
     $follower = $from_user;
     $qr_mgr = new UserManager('');
     $userInfo = $qr_mgr->getUserInfo($follower);
     if (empty($userInfo) or empty($userInfo['nickname']) or empty($userInfo['avatar'])) {
         $weapi = new WechatAPI();
         $userInfo = $weapi->getUserInfo($follower);
         $qr_mgr->saveUserInfo($userInfo);
     }
     WeUtility::logging('refresh', $userInfo);
 }
Пример #7
0
 public static function curl_file_get_contents($durl)
 {
     $r = null;
     if (function_exists('curl_init') && function_exists('curl_exec')) {
         WeUtility::logging("using curl");
         $ch = curl_init();
         curl_setopt($ch, CURLOPT_URL, $durl);
         curl_setopt($ch, CURLOPT_TIMEOUT, 5);
         curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:9.0.1) Gecko/20100101 Firefox/9.0.1');
         curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
         $r = curl_exec($ch);
         curl_close($ch);
     }
     return $r;
 }
Пример #8
0
 public static function fsock_http_request($url, $timeout = 30)
 {
     $parsed = parse_url($url);
     $host = $parsed['host'];
     $path = $parsed['path'] . '?' . $parsed['query'];
     $cookie = '';
     $fp = fsockopen($host, 80, $errno, $errstr, $timeout);
     WeUtility::logging('fsockopen', array($url, $errno, $errstr, $fp));
     if (!$fp) {
         return -1;
     }
     $out = "GET " . $path . " HTTP/1.1\r\n";
     $out .= "Host: " . $host . "\r\n";
     $out .= "Connection: Close\r\n";
     $out .= "Cookie: " . $cookie . "\r\n\r\n";
     fwrite($fp, $out);
     fclose($fp);
 }
Пример #9
0
 private function notifyUpLevel($weapi, $this_level_openid)
 {
     global $_W;
     WeUtility::logging('notifyUpLevel begin', $this_level_openid);
     $uplevel = pdo_fetch("SELECT * FROM " . tablename(self::$t_follow) . " WHERE weid=:weid AND follower=:follower", array(":weid" => $_W['weid'], ":follower" => $this_level_openid));
     WeUtility::logging('notifyUpLevel begin2', $this_level_openid);
     if (!empty($uplevel)) {
         $fans = WechatUtil::fans_search($this_level_openid, array('nickname'));
         WeUtility::logging('notifyUpLevel sendText begin', $uplevel['leader']);
         $weapi->sendText($uplevel['leader'], '您的朋友' . $fans['nickname'] . '又获得了一个新的支持者,您也得到了相应积分奖励,请注意查收!');
     }
     WeUtility::logging('notifyUpLevel', $uplevel);
 }
Пример #10
0
 public function start()
 {
     global $_W;
     if (empty($this->account)) {
         exit('Miss Account.');
     }
     if (!$this->account->checkSign()) {
         exit('Check Sign Fail.');
     }
     if (strtolower($_SERVER['REQUEST_METHOD']) == 'get') {
         $row = array();
         $row['isconnect'] = 1;
         pdo_update('account', $row, array('acid' => $_W['acid']));
         exit(htmlspecialchars($_GET['echostr']));
     }
     if (strtolower($_SERVER['REQUEST_METHOD']) == 'post') {
         $postStr = file_get_contents('php://input');
         if (!empty($_GET['encrypt_type']) && $_GET['encrypt_type'] == 'aes') {
             $postStr = $this->account->decryptMsg($postStr);
         }
         WeUtility::logging('trace', $postStr);
         $message = $this->account->parse($postStr);
         $this->message = $message;
         if (empty($message)) {
             WeUtility::logging('waring', 'Request Failed');
             exit('Request Failed');
         }
         $_W['openid'] = $message['from'];
         $_W['fans'] = array('from_user' => $_W['openid']);
         $this->booking($message);
         if ($message['event'] == 'unsubscribe') {
             $this->receive(array(), array(), array());
             exit;
         }
         $sessionid = md5($message['from'] . $message['to'] . $_W['uniacid']);
         session_id($sessionid);
         WeSession::start($_W['uniacid'], $_W['openid']);
         $_SESSION['openid'] = $_W['openid'];
         $pars = $this->analyze($message);
         $pars[] = array('message' => $message, 'module' => 'default', 'rule' => '-1');
         $hitParam['rule'] = -2;
         $hitParam['module'] = '';
         $hitParam['message'] = $message;
         $hitKeyword = array();
         $response = array();
         foreach ($pars as $par) {
             if (empty($par['module'])) {
                 continue;
             }
             $par['message'] = $message;
             $response = $this->process($par);
             if ($this->isValidResponse($response)) {
                 $hitParam = $par;
                 if (!empty($par['keyword'])) {
                     $hitKeyword = $par['keyword'];
                 }
                 break;
             }
         }
         $response_debug = $response;
         $pars_debug = $pars;
         if ($hitParam['module'] == 'default' && is_array($response) && is_array($response['params'])) {
             foreach ($response['params'] as $par) {
                 if (empty($par['module'])) {
                     continue;
                 }
                 $response = $this->process($par);
                 if ($this->isValidResponse($response)) {
                     $hitParam = $par;
                     if (!empty($par['keyword'])) {
                         $hitKeyword = $par['keyword'];
                     }
                     break;
                 }
             }
         }
         WeUtility::logging('params', $hitParam);
         WeUtility::logging('response', $response);
         $resp = $this->account->response($response);
         if (!empty($_GET['encrypt_type']) && $_GET['encrypt_type'] == 'aes') {
             $resp = $this->account->encryptMsg($resp);
             $resp = $this->account->xmlDetract($resp);
         }
         if ($_W['debug']) {
             $_W['debug_data'] = array('resp' => $resp, 'is_default' => 0);
             if (count($pars_debug) == 1) {
                 $_W['debug_data']['is_default'] = 1;
                 $_W['debug_data']['params'] = $response_debug['params'];
             } else {
                 array_pop($pars_debug);
                 $_W['debug_data']['params'] = $pars_debug;
             }
             $_W['debug_data']['hitparam'] = $hitParam;
             $_W['modules']['cover'] = array('title' => '入口封面', 'name' => 'cover');
             load()->web('template');
             $process = template('utility/emulator', TEMPLATE_FETCH);
             echo json_encode(array('resp' => $resp, 'process' => $process));
             exit;
         }
         ob_start();
         echo $resp;
         ob_start();
         $this->receive($hitParam, $hitKeyword, $response);
         ob_end_clean();
         exit;
     }
     WeUtility::logging('waring', 'Request Failed');
     exit('Request Failed');
 }
Пример #11
0
$notify->saveData($input);
$data = $notify->getData();
$ordersetting = DBUtil::findUnique(DBUtil::$TABLE_ORDER_SETTING, array(":appid" => $data['appid']));
if (empty($data)) {
    $notify->setReturnParameter("return_code", "FAIL");
    $notify->setReturnParameter("return_msg", "通用订单参数格式校验错误");
    WeUtility::logging('info', "通用订单回复参数格式校验错误");
    exit($notify->createXml());
}
if ($data['result_code'] != 'SUCCESS' || $data['return_code'] != 'SUCCESS') {
    $notify->setReturnParameter("return_code", "FAIL");
    $notify->setReturnParameter("return_msg", "通用订单参数格式校验错误");
    WeUtility::logging('info', "通用订单回复参数格式校验错误");
    exit($notify->createXml());
}
//更新表订单信息
WeUtility::logging('info', "通知订单更新");
if ($notify->checkSign($ordersetting['shkey'])) {
    DBUtil::update(DBUtil::$TABLE_ORDER_ORDER, array("status" => 3, 'paytime' => TIMESTAMP), array("outno" => $data['out_trade_no']));
    $order = DBUtil::findUnique(DBUtil::$TABLE_ORDER_ORDER, array(":outno" => $data['out_trade_no']));
    $notify->setReturnParameter("return_code", "SUCCESS");
    $notify->setReturnParameter("return_msg", "OK");
    exit($notify->createXml());
} else {
    $notify->setReturnParameter("return_code", "FAIL");
    $notify->setReturnParameter("return_msg", "通用订单签名校验错误");
    WeUtility::logging('info', "通用订单签名校验错误");
    exit($notify->createXml());
}
WeUtility::logging('info', "通用订单更新回复数据" . $data);
Пример #12
0
 private function trackAccess($detail)
 {
     global $_W, $_GPC;
     $credit_cost = 0;
     if (!isset($_GPC['shareby'])) {
         return;
     }
     $shareby = $_GPC['shareby'];
     $track_type = $_GPC['track_type'];
     $track_msg = $_GPC['track_msg'];
     $credit = 0;
     $clicker_id = $_W['fans']['from_user'];
     $fans = $this->fans_search($shareby);
     if (empty($fans)) {
         return -1;
     }
     if (true) {
         $cookie_name = "xc_article-1-" . $_W['weid'];
         if (isset($_COOKIE[$cookie_name])) {
             return 0;
         } else {
             setcookie($cookie_name, 'killed', TIMESTAMP + $this->module['config']['prohibit_site_click_interval']);
         }
     }
     if (true) {
         $cookie_name = "xc_article-1-" . $_W['weid'] . "-" . $shareby . "-" . $detail['id'];
         if (isset($_COOKIE[$cookie_name])) {
             return 0;
         } else {
             setcookie($cookie_name, 'killed', TIMESTAMP + $this->module['config']['prohibit_single_article_click_interval']);
         }
     }
     $click_history = pdo_fetch("SELECT * FROM  " . tablename('xc_article_share_track') . " WHERE weid=:weid AND shareby=:shareby AND detail_id=:detail_id AND track_type=:track_type AND clicker_id=:clicker_id", array(':weid' => $_W['weid'], ':shareby' => $shareby, ':detail_id' => $detail['id'], ':track_type' => 'click', ':clicker_id' => $clicker_id));
     if (!empty($click_history)) {
         return 0;
     }
     $per_user_credit = pdo_fetch("SELECT SUM(credit) as total_credit FROM " . tablename('xc_article_share_track') . " WHERE detail_id = :detail_id AND shareby=:shareby", array(':detail_id' => $detail['id'], ':shareby' => $shareby));
     if ($track_type == 'click' and $detail['click_credit'] > 0) {
         if (0 >= $detail['max_credit'] or $detail['per_user_credit'] > 0 and $per_user_credit['total_credit'] >= $detail['per_user_credit']) {
             $credit = 0;
         } else {
             $credit = $detail['click_credit'];
             $credit_cost += $credit;
         }
         $this->addCredit($shareby, $credit);
         pdo_insert('xc_article_share_track', array('weid' => $_W['weid'], 'credit' => $credit, 'shareby' => $shareby, 'track_type' => $track_type, 'track_msg' => $track_msg, 'detail_id' => $detail['id'], 'title' => $detail['title'], 'access_time' => TIMESTAMP, 'ip' => getip(), 'clicker_id' => $clicker_id));
     }
     if ($track_type == 'click' and $detail['share_credit'] > 0 and !empty($shareby)) {
         if ($credit >= $detail['max_credit']) {
             $credit = 0;
         } else {
             $credit = $detail['share_credit'];
             $credit_cost += $credit;
         }
         $share_credit_info = pdo_fetch("SELECT * FROM  " . tablename('xc_article_share_track') . " WHERE weid=:weid AND shareby=:shareby AND detail_id=:detail_id AND track_type=:track_type", array(':weid' => $_W['weid'], ':shareby' => $shareby, ':detail_id' => $detail['id'], ':track_type' => 'share'));
         if (false == $share_credit_info) {
             $this->addCredit($shareby, $credit);
             pdo_insert('xc_article_share_track', array('weid' => $_W['weid'], 'credit' => $credit, 'shareby' => $shareby, 'track_type' => 'share', 'track_msg' => $track_msg, 'detail_id' => $detail['id'], 'title' => $detail['title'], 'access_time' => TIMESTAMP, 'ip' => getip(), 'clicker_id' => $clicker_id));
         }
     }
     if ($credit_cost > 0 and !empty($detail['id'])) {
         $sql = "UPDATE " . tablename('xc_article_article') . " SET max_credit = max_credit - " . $credit_cost . " WHERE id=:id AND weid=:weid";
         pdo_query($sql, array(":weid" => $_W['weid'], ":id" => $detail['id']));
     }
     WeUtility::logging('byebye ' . $shareby);
 }
Пример #13
0
 public function start()
 {
     global $_W;
     if (empty($this->token)) {
         exit('Access Denied');
     }
     if (!WeUtility::checkSign($this->token)) {
         exit('Access Denied');
     }
     if (strtolower($_SERVER['REQUEST_METHOD']) == 'get') {
         ob_clean();
         ob_start();
         exit($_GET['echostr']);
     }
     if (strtolower($_SERVER['REQUEST_METHOD']) == 'post') {
         $postStr = $GLOBALS["HTTP_RAW_POST_DATA"];
         $this->message = WeUtility::parse($postStr);
         if (empty($this->message)) {
             WeUtility::logging('waring', 'Request Failed');
             exit('Request Failed');
         }
         $sessionid = md5($this->message['from'] . $this->message['to'] . $_W['weid']);
         session_id($sessionid);
         WeSession::$weid = $_W['weid'];
         WeSession::$from = $this->message['from'];
         WeSession::$expire = 3600;
         WeSession::start();
         WeUtility::logging('trace', $this->message);
         $pars = $this->matcher();
         $pars[] = array('module' => 'default', 'rule' => '-1');
         foreach ($pars as $par) {
             if (empty($par['module'])) {
                 continue;
             }
             $this->params = $par;
             $this->response = $this->process();
             if (is_array($this->response) && ($this->response['type'] == 'text' && !empty($this->response['content']) || $this->response['type'] == 'news' && !empty($this->response['items']) || !in_array($this->type, array('text', 'news')))) {
                 if (!empty($par['keyword'])) {
                     $this->keyword = $par['keyword'];
                 }
                 break;
             }
         }
         WeUtility::logging('params', $this->params);
         WeUtility::logging('response', $this->response);
         $resp = WeUtility::response($this->response);
         $mapping = array('[from]' => $this->message['from'], '[to]' => $this->message['to'], '[rule]' => $this->params['rule']);
         echo str_replace(array_keys($mapping), array_values($mapping), $resp);
         $subscribes = array();
         foreach ($_W['account']['modules'] as $m) {
             if (in_array($m['name'], $this->modules) && is_array($m['subscribes']) && !empty($m['subscribes'])) {
                 $subscribes[] = $m;
             }
         }
         if (!empty($subscribes)) {
             $this->subscribe($subscribes);
         }
         exit;
     }
     WeUtility::logging('waring', 'Request Failed');
     exit('Request Failed');
 }
Пример #14
0
 */
$input = file_get_contents('php://input');
if (preg_match('/(\\<\\!DOCTYPE|\\<\\!ENTITY)/i', $input)) {
    exit('fail');
}
libxml_disable_entity_loader(true);
$obj = simplexml_load_string($input, 'SimpleXMLElement', LIBXML_NOCDATA);
if ($obj instanceof SimpleXMLElement && !empty($obj->FeedBackId)) {
    $data = array('openid' => trim($obj->OpenId), 'appid' => trim($obj->AppId), 'timestamp' => trim($obj->TimeStamp), 'msgtype' => trim($obj->MsgType), 'feedbackid' => trim($obj->FeedBackId), 'transid' => trim($obj->TransId), 'reason' => trim($obj->Reason), 'solution' => trim($obj->Solution), 'extinfo' => trim($obj->ExtInfo), 'appsignature' => trim($obj->AppSignature), 'signmethod' => trim($obj->SignMethod));
    if (!empty($obj->PicInfo) && !empty($obj->PicInfo->item)) {
        foreach ($obj->PicInfo->item as $item) {
            $data['picinfo'][] = trim($item->PicUrl);
        }
    }
    require '../../framework/bootstrap.inc.php';
    WeUtility::logging('pay-rights', $input);
    $_W['uniacid'] = pdo_fetchcolumn("SELECT uniacid FROM " . tablename('account_wechats') . " WHERE `key` = :key", array(':key' => $data['appid']));
    $setting = uni_setting($_W['uniacid'], array('payment'));
    $_W['weid'] = $_W['uniacid'];
    if (empty($setting['payment'])) {
        exit('failed');
    }
    $data['appkey'] = $setting['payment']['wechat']['signkey'];
    if (!checkSign($data)) {
        exit('failed');
    }
    if ($data['msgtype'] == 'request') {
        $insert = array('weid' => $_W['weid'], 'openid' => $data['openid'], 'feedbackid' => $data['feedbackid'], 'transid' => $data['transid'], 'reason' => $data['reason'], 'solution' => $data['solution'], 'remark' => $data['extinfo'], 'createtime' => $data['timestamp'], 'status' => 0);
        pdo_insert('shopping_feedback', $insert);
        exit('success');
    } elseif ($data['msgtype'] == 'confirm') {
Пример #15
0
 public function saveUserInfo($info)
 {
     if (!isset($info['subscribe']) || $info['subscribe'] != 1) {
         return;
     }
     WeUtility::logging('saveUserInfo', $info);
     $from_user = $info['openid'];
     load()->model('mc');
     $uid = mc_openid2uid($from_user);
     mc_update($uid, array('nickname' => $info['nickname'], 'gender' => $info['sex'], 'nationality' => $info['country'], 'resideprovince' => $info['province'], 'residecity' => $info['city'], 'avatar' => $info['headimgurl']));
 }
Пример #16
0
$notify = new Notify_pub();
$notify->saveData($input);
$data = $notify->getData();
$kjsetting = DBUtil::findUnique(DBUtil::$TABLE_WKJ_SETTING, array(":appid" => $data['appid']));
if (empty($data)) {
    $notify->setReturnParameter("return_code", "FAIL");
    $notify->setReturnParameter("return_msg", "参数格式校验错误");
    WeUtility::logging('info', "微砍价回复参数格式校验错误");
    exit($notify->createXml());
}
if ($data['result_code'] != 'SUCCESS' || $data['return_code'] != 'SUCCESS') {
    $notify->setReturnParameter("return_code", "FAIL");
    $notify->setReturnParameter("return_msg", "参数格式校验错误");
    WeUtility::logging('info', "微砍价回复参数格式校验错误");
    exit($notify->createXml());
}
//更新表订单信息
WeUtility::logging('info', "通知订单更新");
if ($notify->checkSign($kjsetting['shkey'])) {
    DBUtil::update(DBUtil::$TABLE_WJK_ORDER, array("status" => 4, 'notifytime' => TIMESTAMP, 'wxnotify' => $data, 'wxorder_no' => $data['transaction_id']), array("order_no" => $data['out_trade_no']));
    $notify->setReturnParameter("return_code", "SUCCESS");
    $notify->setReturnParameter("return_msg", "OK");
    exit($notify->createXml());
} else {
    $notify->setReturnParameter("return_code", "FAIL");
    $notify->setReturnParameter("return_msg", "签名校验错误");
    WeUtility::logging('info', "签名校验错误");
    exit($notify->createXml());
}
WeUtility::logging('info', "微砍价回复数据" . $data);
Пример #17
0
 private function getQRTicket($token, $data)
 {
     $url = "https://api.weixin.qq.com/cgi-bin/qrcode/create?access_token={$token}";
     WeUtility::logging('QR data', json_encode($data));
     $ret = WechatUtil::http_request($url, json_encode($data));
     $content = @json_decode($ret['content'], true);
     WeUtility::logging('QR content', $content);
     return $content;
 }
Пример #18
0
 public function openPlatformTestCase()
 {
     global $_GPC;
     $post = file_get_contents('php://input');
     WeUtility::logging('platform-test-message', $post);
     $encode_message = $this->xmlExtract($post);
     $message = aes_decode($encode_message['encrypt'], $this->encodingaeskey);
     $message = $this->parse($message);
     $response = array('ToUserName' => $message['from'], 'FromUserName' => $message['to'], 'CreateTime' => TIMESTAMP, 'MsgId' => TIMESTAMP, 'MsgType' => 'text');
     if ($message['content'] == 'TESTCOMPONENT_MSG_TYPE_TEXT') {
         $response['Content'] = 'TESTCOMPONENT_MSG_TYPE_TEXT_callback';
     }
     if ($message['msgtype'] == 'event') {
         $response['Content'] = $message['event'] . 'from_callback';
     }
     if (strexists($message['content'], 'QUERY_AUTH_CODE')) {
         list($sufixx, $authcode) = explode(':', $message['content']);
         $auth_info = $this->getAuthInfo($authcode);
         WeUtility::logging('platform-test-send-message', var_export($auth_info, true));
         $url = "https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token=" . $auth_info['authorization_info']['authorizer_access_token'];
         $data = array('touser' => $message['from'], 'msgtype' => 'text', 'text' => array('content' => $authcode . '_from_api'));
         $response = ihttp_request($url, urldecode(json_encode($data)));
         exit('');
     }
     $xml = array('Nonce' => $_GPC['nonce'], 'TimeStamp' => $_GPC['timestamp'], 'Encrypt' => aes_encode(array2xml($response), $this->encodingaeskey, $this->appid));
     $signature = array($xml['Encrypt'], $this->token, $_GPC['timestamp'], $_GPC['nonce']);
     sort($signature, SORT_STRING);
     $signature = implode($signature);
     $xml['MsgSignature'] = sha1($signature);
     exit(array2xml($xml));
 }
Пример #19
0
 /**
  * 识别人脸信息:性别(gender), 年龄(age), 种族(race), 微笑程度(smiling), 眼镜(glass)和姿势(pose)
  * @param 	string $faceImg 图片地址
  * @return	
  */
 public function getFaceDetect($faceImg)
 {
     //查询内容
     $faces = array();
     $attr = 'glass,pose,gender,age,race,smiling';
     $url = self::FACEPLUS_URL . self::API_VERSION . self::API_FUNC_DETECT . 'api_key=' . self::API_KEY . '&api_secret=' . self::API_SECRET . '&url=' . $faceImg . '&attribute=' . $attr;
     WeUtility::logging('tips', 'req-url:' . $url);
     //获取信息
     if ($retVal = file_get_contents($url)) {
         $retVal = json_decode($retVal, true);
         //人脸列表
         $faceres = $retVal['face'];
         foreach ($faceres as $key => $value) {
             //degug
             $faces[$key]['age'] = $value['attribute']['age']['value'];
             if (0 >= $value['attribute']['smiling']['value']) {
                 $faces[$key]['smile'] = '难过';
             } else {
                 if (0 < $value['attribute']['smiling']['value'] && 20 >= $value['attribute']['smiling']['value']) {
                     $faces[$key]['smile'] = '一般';
                 } else {
                     if (20 < $value['attribute']['smiling']['value'] && 40 >= $value['attribute']['smiling']['value']) {
                         $faces[$key]['smile'] = '不错';
                     } else {
                         if (40 < $value['attribute']['smiling']['value'] && 60 >= $value['attribute']['smiling']['value']) {
                             $faces[$key]['smile'] = '很好';
                         } else {
                             if (60 < $value['attribute']['smiling']['value'] && 80 >= $value['attribute']['smiling']['value']) {
                                 $faces[$key]['smile'] = '非常好';
                             } else {
                                 if (80 < $value['attribute']['smiling']['value'] && 100 >= $value['attribute']['smiling']['value']) {
                                     $faces[$key]['smile'] = '很兴奋';
                                 }
                             }
                         }
                     }
                 }
             }
             //性别判断
             if (60 <= $value['attribute']['gender']['confidence']) {
                 if ('Female' == $value['attribute']['gender']['value']) {
                     $faces[$key]['gender'] = '女性';
                 } else {
                     $faces[$key]['gender'] = '男性';
                 }
             } else {
                 $faces[$key]['gender'] = '未知';
             }
             //是否佩戴眼镜
             if (60 <= $value['attribute']['glass']['confidence']) {
                 if ('Normal' == $value['attribute']['glass']['value']) {
                     $faces[$key]['glass'] = '普通眼镜';
                 } else {
                     if ('Dark' == $value['attribute']['glass']['value']) {
                         $faces[$key]['glass'] = '墨镜';
                     } else {
                         $faces[$key]['glass'] = '';
                     }
                 }
             } else {
                 $faces[$key]['glass'] = '';
             }
             //人种
             if (60 <= $value['attribute']['race']['confidence']) {
                 if ('Asian' == $value['attribute']['race']['value']) {
                     $faces[$key]['race'] = '亚洲人';
                 } else {
                     if ('White' == $value['attribute']['race']['value']) {
                         $faces['$key']['race'] = '欧美人';
                     } else {
                         $faces[$key]['race'] = '非洲人';
                     }
                 }
             } else {
                 $faces[$key]['race'] = '外星人';
             }
             //面部动作
         }
         return $faces;
     } else {
         //degug
         //查询失败
         return false;
     }
 }
Пример #20
0
 public function doMobileOAuth()
 {
     global $_W, $_GPC;
     $account = $this->getAccount();
     $code = trim($_GPC['code']);
     if (!empty($code)) {
         $url = "https://api.weixin.qq.com/sns/oauth2/access_token?appid={$account['key']}&secret={$account['secret']}&code={$code}&grant_type=authorization_code";
         WeUtility::logging('trace', 'url:' . $url);
         $ret = ihttp_get($url);
         if (!is_error($ret)) {
             $auth = @json_decode($ret['content'], true);
             if (is_array($auth) && !empty($auth['openid'])) {
                 $row = array();
                 $row['weid'] = $_W['weid'];
                 $row['openid'] = $auth['openid'];
                 $row['from_user'] = $auth['openid'];
                 if ($auth['scope'] == 'snsapi_userinfo') {
                     $user = $this->getFansInfo($auth['access_token'], $auth['openid']);
                     $row['nickname'] = $user['nickname'];
                     $row['avatar'] = $user['headimgurl'];
                 }
                 WeUtility::logging('trace', 'user:'******'query']);
                 header('location: ' . $_W['siteroot'] . 'mobile.php?' . $forward . '&' . $this->cookiename . '=' . $auth['openid'] . '&wxref=mp.weixin.qq.com#wechat_redirect');
                 exit;
             } else {
                 message($ret['content']);
             }
         }
     }
     message('微信授权失败!');
 }
Пример #21
0
    }
    if ($data['result_code'] != 'SUCCESS' || $data['return_code'] != 'SUCCESS') {
        $result = array('return_code' => 'FAIL', 'return_msg' => empty($data['return_msg']) ? $data['err_code_des'] : $data['return_msg']);
        echo array2xml($result);
        exit;
    }
    $get = $data;
} else {
    $isxml = false;
    $get = $_GET;
}
$_W['uniacid'] = $_W['weid'] = $get['attach'];
$setting = uni_setting($_W['uniacid'], array('payment'));
if (is_array($setting['payment'])) {
    $wechat = $setting['payment']['wechat'];
    WeUtility::logging('pay', var_export($get, true));
    if (!empty($wechat)) {
        ksort($get);
        $string1 = '';
        foreach ($get as $k => $v) {
            if ($v != '' && $k != 'sign') {
                $string1 .= "{$k}={$v}&";
            }
        }
        $wechat['signkey'] = $wechat['version'] == 1 ? $wechat['key'] : $wechat['signkey'];
        $sign = strtoupper(md5($string1 . "key={$wechat['signkey']}"));
        if ($sign == $get['sign']) {
            $sql = 'SELECT * FROM ' . tablename('core_paylog') . ' WHERE `uniontid`=:uniontid';
            $params = array();
            $params[':uniontid'] = $get['out_trade_no'];
            $log = pdo_fetch($sql, $params);
Пример #22
0
 /**
  * author: 微赞
  * @param $order
  * @param $item
  * 发送模板消息
  */
 public function sendPayTemplateMsg($order, $item)
 {
     $template = $this->findTemplateSetting();
     if ($template['payenable'] == 1) {
         $templateMsg = array();
         $templateMsg['template_id'] = $template['paytid'];
         $templateMsg['touser'] = $order['openid'];
         $templateMsg['url'] = MonUtil::str_murl($this->createMobileUrl('OrderItem', array('openid' => $order['openid'], 'iid' => $item['id']), true));
         $templateMsg['topcolor'] = '#FF0000';
         $data = array();
         $data['first'] = array('value' => "恭喜" . $order['uname'] . "支付" . $item['iname'] . "成功!", 'color' => '#173177');
         $data['orderMoneySum'] = array('value' => $order['zf_price'], 'color' => '#173177');
         $data['orderProductName'] = array('value' => $item['iname'], 'color' => '#173177');
         $data['remark'] = array('value' => "保存好您的支付凭证哦!欢迎下次再次预定", 'color' => '#173177');
         $templateMsg['data'] = $data;
         $jsonData = json_encode($templateMsg);
         WeUtility::logging('info', "发送模板消息数据" . $jsonData);
         load()->func('communication');
         $acessToken = $this->getAccessToken();
         $apiUrl = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=" . $acessToken;
         $result = ihttp_request($apiUrl, $jsonData);
         WeUtility::logging('info', "发送支付消息返回内容" . $result);
     }
 }
Пример #23
0
 public function start()
 {
     global $_W;
     if (empty($this->account)) {
         exit('Miss Account.');
     }
     if (!$this->account->checkSign()) {
         exit('Check Sign Fail.');
     }
     if (strtolower($_SERVER['REQUEST_METHOD']) == 'get') {
         $row = array();
         $row['isconnect'] = 1;
         pdo_update('account', $row, array('acid' => $_W['acid']));
         exit($_GET['echostr']);
     }
     if (strtolower($_SERVER['REQUEST_METHOD']) == 'post') {
         $postStr = file_get_contents('php://input');
         if (!empty($_GET['encrypt_type']) && $_GET['encrypt_type'] == 'aes') {
             $postStr = $this->account->decryptMsg($postStr);
         }
         $message = $this->account->parse($postStr);
         $this->message = $message;
         if (empty($message)) {
             WeUtility::logging('waring', 'Request Failed');
             exit('Request Failed');
         }
         $_W['openid'] = $message['from'];
         $_W['fans'] = array('from_user' => $_W['openid']);
         $this->booking($message);
         if ($message['event'] == 'unsubscribe') {
             $this->receive(array(), array(), array());
             exit;
         }
         $sessionid = md5($message['from'] . $message['to'] . $_W['uniacid']);
         session_id($sessionid);
         WeSession::start($_W['uniacid'], $_W['openid']);
         $_SESSION['openid'] = $_W['openid'];
         WeUtility::logging('trace', $message);
         $pars = $this->analyze($message);
         $pars[] = array('message' => $message, 'module' => 'default', 'rule' => '-1');
         $hitParam['rule'] = -2;
         $hitParam['module'] = '';
         $hitParam['message'] = $message;
         $hitKeyword = array();
         $response = array();
         foreach ($pars as $par) {
             if (empty($par['module'])) {
                 continue;
             }
             $par['message'] = $message;
             $response = $this->process($par);
             if ($this->isValidResponse($response)) {
                 $hitParam = $par;
                 if (!empty($par['keyword'])) {
                     $hitKeyword = $par['keyword'];
                 }
                 break;
             }
         }
         if ($hitParam['module'] == 'default' && is_array($response) && is_array($response['params'])) {
             foreach ($response['params'] as $par) {
                 if (empty($par['module'])) {
                     continue;
                 }
                 $response = $this->process($par);
                 if ($this->isValidResponse($response)) {
                     $hitParam = $par;
                     if (!empty($par['keyword'])) {
                         $hitKeyword = $par['keyword'];
                     }
                     break;
                 }
             }
         }
         WeUtility::logging('params', $hitParam);
         WeUtility::logging('response', $response);
         $resp = $this->account->response($response);
         $resp = $this->clip($resp, $hitParam);
         if (!empty($_GET['encrypt_type']) && $_GET['encrypt_type'] == 'aes') {
             $resp = $this->account->encryptMsg($resp);
             $resp = $this->account->xmlDetract($resp);
         }
         echo $resp;
         ob_flush();
         flush();
         $this->receive($hitParam, $hitKeyword, $response);
         ob_end_clean();
         exit;
     }
     WeUtility::logging('waring', 'Request Failed');
     exit('Request Failed');
 }
Пример #24
0
    pdo_insert('account_wechats', $subaccount_insert);
    if (is_error($acid)) {
        message('授权登录新建公众号失败,请重试', url('account/display'), 'error');
    }
    if (empty($_W['isfounder'])) {
        pdo_insert('uni_account_users', array('uniacid' => $uniacid, 'uid' => $_W['uid'], 'role' => 'owner'));
    }
    pdo_update('uni_account', array('default_acid' => $acid), array('uniacid' => $uniacid));
    $headimg = ihttp_request($account_info['authorizer_info']['head_img']);
    $qrcode = ihttp_request($account_info['authorizer_info']['qrcode_url']);
    file_put_contents(IA_ROOT . '/attachment/headimg_' . $acid . '.jpg', $headimg['content']);
    file_put_contents(IA_ROOT . '/attachment/qrcode_' . $acid . '.jpg', $qrcode['content']);
    message('授权登录成功', url('account/display'), 'success');
} elseif ($do == 'ticket') {
    $post = file_get_contents('php://input');
    WeUtility::logging('debug', 'account-ticket' . $post);
    $encode_ticket = isimplexml_load_string($post, 'SimpleXMLElement', LIBXML_NOCDATA);
    if (empty($post) || empty($encode_ticket)) {
        exit('fail');
    }
    $decode_ticket = aes_decode($encode_ticket->Encrypt, $setting['platform']['encodingaeskey']);
    $ticket_xml = isimplexml_load_string($decode_ticket, 'SimpleXMLElement', LIBXML_NOCDATA);
    if (empty($ticket_xml)) {
        exit('fail');
    }
    cache_write('account:ticket', strval($ticket_xml->ComponentVerifyTicket));
    exit('success');
} elseif ($do == 'test') {
    $authurl = $account_platform->getAuthLoginUrl();
    echo '<a href="' . $authurl . '%26test=1"><img src="https://open.weixin.qq.com/zh_CN/htmledition/res/assets/res-design-download/icon_button3_2.png" /></a>';
}
Пример #25
0
 private function genImage($weapi, $scene_id, $channel, $from_user)
 {
     global $_W;
     $rand_file = $from_user . rand() . '.jpg';
     $att_target_file = 'qr-image-' . $rand_file;
     $att_head_cache_file = 'head-image-' . $rand_file;
     $target_file = ATTACH_DIR . $att_target_file;
     $target_file_url = $_W['attachurl'] . $att_target_file;
     $head_cache_file = ATTACH_DIR . $att_head_cache_file;
     $qr_file = $weapi->getLimitQR($scene_id);
     $ch = pdo_fetch("SELECT * FROM " . tablename(self::$t_channel) . " WHERE channel=:channel AND weid=:weid", array(":channel" => $channel, ":weid" => $_W['weid']));
     $ch = WechatUtil::decode_channel_param($ch, $ch['bgparam']);
     $enableHead = $ch['avatarenable'];
     $enableName = $ch['nameenable'];
     if (empty($ch)) {
         $ret = $weapi->sendText($from_user, "您所请求的专属海报二维码已经失效, 请联系客服人员");
         exit(0);
     } else {
         if (empty($ch['bg'])) {
             $bg_file = APP_PHP . 'images/bg.jpg';
         } else {
             $bg_file = $_W['attachurl'] . $ch['bg'];
         }
     }
     // 基础模式
     WeUtility::logging('step merge 1', "merge bgfile {$bg_file} and qrfile {$qr_file}");
     $this->mergeImage($bg_file, $qr_file, $target_file, array('left' => $ch['qrleft'], 'top' => $ch['qrtop'], 'width' => $ch['qrwidth'], 'height' => $ch['qrheight']));
     WeUtility::logging('step merge 1 done', '');
     // 扩展功能:昵称、图像
     if (1) {
         $fans = WechatUtil::fans_search($from_user, array('nickname', 'avatar'));
         if (!empty($fans)) {
             // 昵称
             if ($enableName) {
                 if (strlen($fans['nickname']) > 0) {
                     WeUtility::logging('step wirte text 1', $fans);
                     // $this->writeText($target_file, $target_file, '我是' . $fans['nickname'], array('size'=>30, 'left'=>150, 'top'=>50));
                     $this->writeText($target_file, $target_file, $fans['nickname'], array('size' => $ch['namesize'], 'left' => $ch['nameleft'], 'top' => $ch['nametop']));
                     WeUtility::logging('step wirte text 1 done', '');
                 }
             }
             // 头像
             if ($enableHead) {
                 if (strlen($fans['avatar']) > 10) {
                     $head_file = $fans['avatar'];
                     $head_file = preg_replace('/\\/0$/i', '/96', $head_file);
                     WeUtility::logging('step merge 2', $head_file);
                     $this->mergeImage($target_file, $head_file, $target_file, array('left' => $ch['avatarleft'], 'top' => $ch['avatartop'], 'width' => $ch['avatarwidth'], 'height' => $ch['avatarheight']));
                     WeUtility::logging('step merge 2 done', '');
                     WeUtility::logging('IamInMergeFile', $target_file . $head_file);
                 } else {
                     WeUtility::logging('NoAvatarFile', $fans['avatar']);
                 }
             }
         } else {
             WeUtility::logging('NOT merge avatar and nickname', $from_user);
         }
     }
     WeUtility::logging('step upload 1', '');
     $media_id = $weapi->uploadImage($target_file);
     WeUtility::logging('step upload 1 done', '');
     WeUtility::logging('genImage', $media_id);
     if (!empty($media_id)) {
         $nowtime = time();
         pdo_query("INSERT INTO " . tablename('core_attachment') . " (uniacid,uid,filename,attachment,type,createtime) VALUES " . "({$_W['weid']}, {$_W['weid']}, 'head_cache', '{$att_head_cache_file}', 1, {$nowtime})," . "({$_W['weid']}, {$_W['weid']}, 'post_cache', '{$att_target_file}', 1, {$nowtime})");
     } else {
         // in case 45009, api freq out of limit ;
         $ret = $weapi->sendText($from_user, "专属二维码已经生成, 点击这里:<a href='{$target_file_url}'>查看您的专属二维码</a>, 保存到手机后转发给好友就能拿话费!");
     }
     return array($media_id, $target_file_url);
 }
Пример #26
0
<?php

/**
 * [WeEngine System] Copyright (c) 2014 WE7.CC
 * WeEngine is NOT a free software, it under the license terms, visited http://www.we7.cc/ for more details.
 */
require '../../source/bootstrap.inc.php';
$input = file_get_contents('php://input');
$obj = simplexml_load_string($input, 'SimpleXMLElement', LIBXML_NOCDATA);
if ($obj instanceof SimpleXMLElement && !empty($obj->FeedBackId)) {
    $data = array('appid' => trim($obj->AppId), 'timestamp' => trim($obj->TimeStamp), 'errortype' => trim($obj->ErrorType), 'description' => trim($obj->Description), 'alarmcontent' => trim($obj->AlarmContent), 'appsignature' => trim($obj->AppSignature), 'signmethod' => trim($obj->SignMethod));
    require '../../framework/bootstrap.inc.php';
    WeUtility::logging('pay-warning', $input);
}
exit('success');