コード例 #1
0
ファイル: WeixinAction.class.php プロジェクト: SubDong/pigcms
 public function index()
 {
     if (!class_exists('SimpleXMLElement')) {
         exit('SimpleXMLElement class not exist');
     }
     if (!function_exists('dom_import_simplexml')) {
         exit('dom_import_simplexml function not exist');
     }
     $this->token = $this->_get('token', "htmlspecialchars");
     if (!preg_match("/^[0-9a-zA-Z]{3,42}\$/", $this->token)) {
         exit('error token');
     }
     $weixin = new Wechat($this->token);
     $data = $weixin->request();
     $this->data = $weixin->request();
     $this->fans = S('fans_' . $this->token . '_' . $this->data['FromUserName']);
     if (!$this->fans || 1) {
         $this->fans = M('Userinfo')->where(array('token' => $this->token, 'wecha_id' => $this->data['FromUserName']))->find();
         S('fans_' . $this->token . '_' . $this->data['FromUserName'], $this->fans);
     }
     $this->wxuser = S('wxuser_' . $this->token);
     if (!$this->wxuser || 1) {
         $this->wxuser = D('Wxuser')->where(array('token' => $this->token))->find();
         S('wxuser_' . $this->token, $this->wxuser);
     }
     $this->my = C('site_my');
     $this->apiServer = apiServer::getServerUrl();
     $open = M('Token_open')->where(array('token' => $this->_get('token')))->find();
     $this->fun = $open['queryname'];
     list($content, $type) = $this->reply($data);
     $weixin->response($content, $type);
 }
コード例 #2
0
 public function index()
 {
     $this->siteUrl = C('site_url');
     if (!class_exists('SimpleXMLElement')) {
         exit('SimpleXMLElement class not exist');
     }
     if (!function_exists('dom_import_simplexml')) {
         exit('dom_import_simplexml function not exist');
     }
     $this->token = $this->_get('token', "htmlspecialchars");
     if ($this->token == 'pigcms' || $this->token == 'qcloud') {
         $qcloudUser = M('Qcloud_user')->where(array('openid' => $this->_get('openId')))->find();
         $this->token = $qcloudUser['token'];
     }
     if (!preg_match("/^[0-9a-zA-Z]{3,42}\$/", $this->token)) {
         exit('error token');
     }
     $weixin = new Wechat($this->token, $this->wxuser);
     $this->wxuser = S('wxuser_' . $this->token);
     if (!$this->wxuser || 1) {
         $this->wxuser = D('Wxuser')->where(array('token' => $this->token))->find();
         if (C('agent_version') && intval($this->wxuser['agentid'])) {
             $thisAgent = M('Agent')->where(array('id' => $this->wxuser['agentid']))->find();
             $this->siteUrl = $thisAgent['siteurl'];
         }
         S('wxuser_' . $this->token, $this->wxuser);
     }
     $this->user = M('Users')->where(array('id' => $this->wxuser['uid']))->find();
     $weixin = new Wechat($this->token, $this->wxuser);
     $data = $weixin->request();
     $this->data = $weixin->request();
     $this->fans = S('fans_' . $this->token . '_' . $this->data['FromUserName']);
     if (!$this->fans || 1) {
         $this->fans = M('Userinfo')->where(array('token' => $this->token, 'wecha_id' => $this->data['FromUserName']))->find();
         S('fans_' . $this->token . '_' . $this->data['FromUserName'], $this->fans);
     }
     //自定义机器人名字
     $this->my = C('site_my');
     $this->apiServer = apiServer::getServerUrl();
     $open = M('Token_open')->where(array('token' => $this->_get('token')))->find();
     $this->fun = $open['queryname'];
     list($content, $type) = $this->reply($data);
     $weixin->response($content, $type);
 }
コード例 #3
0
    public function index()
    {
		$this->siteUrl = C('site_url');
        if (!class_exists('SimpleXMLElement')) {
            die('SimpleXMLElement class not exist');
        }
        if (!function_exists('dom_import_simplexml')) {
            die('dom_import_simplexml function not exist');
        }
        $this->token = $this->_get('token', 'htmlspecialchars');
        if (!preg_match('/^[0-9a-zA-Z]{3,42}$/', $this->token)) {
            die('error token');
        }
        $this->mykey = trim(C('server_key'));
        $weixin = new Wechat($this->token);
        $data = $weixin->request();
        $this->data = $weixin->request();
        if ($this->data) {
            //自定义机器人名字
            $this->fans = S((('fans_' . $this->token) . '_') . $this->data['FromUserName']);
            if (!$this->fans || 1) {
                $this->fans = M('Userinfo')->where(array('token' => $this->token, 'wecha_id' => $this->data['FromUserName']))->find();
                S((('fans_' . $this->token) . '_') . $this->data['FromUserName'], $this->fans);
            }
            $this->wxuser = S('wxuser_' . $this->token);
            if (!$this->wxuser || 1) {
                $this->wxuser = D('Wxuser')->where(array('token' => $this->token))->find();
                //判断账号是否到期
                $wxuser = M('Wxuser')->where(array('token' => $this->token))->find();
                $users = M('Users')->where(array('id' => $wxuser['uid']))->find();
                if ($users['viptime'] < strtotime(date('Y-m-d H:i:s'))) {
                    $weixin->response('帐号过期,请联系客服!', 'text');
                    return;
                }
                S('wxuser_' . $this->token, $this->wxuser);
            }
            $this->my = C('site_my');
            $this->apiServer = apiServer::getServerUrl();
            $open = M('Token_open')->where(array('token' => $this->_get('token')))->find();
            $this->fun = $open['queryname'];
            list($content, $type) = $this->reply($data);
            $weixin->response($content, $type);
        }
    }
コード例 #4
0
ファイル: WeixinAction.class.php プロジェクト: kevicki/pig
	public function index($ApiData = '')
	{
		if ($ApiData != '') {
			$_GET = $ApiData;
		}

		$this->ali = 0;
		if (isset($_GET['ali']) && intval($_GET['ali'])) {
			$this->ali = 1;
		}

		$this->siteUrl = C('site_url');

		if (!class_exists('SimpleXMLElement')) {
			exit('SimpleXMLElement class not exist');
		}

		if (!function_exists('dom_import_simplexml')) {
			exit('dom_import_simplexml function not exist');
		}

		if (empty($_GET['token']) && isset($_GET['appid'])) {
			$appid = ltrim($_GET['appid'], '/');
			$this->token = M('Wxuser')->where('appid=\'' . $appid . '\'')->getField('token');
		}
		else {
			$this->token = htmlspecialchars($_GET['token']);
		}

		if ($appid == 'wx570bc396a51b8ff8') {
			$wxarr['type'] = 1;
			$wxarr['encode'] = 2;
			$oauth = new Wechat($appid, $wxarr);
			$apiOauth = new apiOauth();
			$data = $oauth->request();
			$openid = $data['FromUserName'];
			$ToUserName = $data['ToUserName'];

			switch ($data['MsgType']) {
			case 'text':
				if ($data['Content'] == 'TESTCOMPONENT_MSG_TYPE_TEXT') {
					$content = 'TESTCOMPONENT_MSG_TYPE_TEXT_callback';
					$oauth->response($content);
				}
				else if (strstr($data['Content'], 'QUERY_AUTH_CODE')) {
					$auth_code = str_replace('QUERY_AUTH_CODE:', '', $data['Content']);
					$authorization_info = $apiOauth->get_authorization_info($auth_code);
					$access_token = $authorization_info['authorizer_access_token'];
					$url = 'https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token=' . $access_token;
					$content = $auth_code . '_from_api';
					$call = '{' . "\r\n" . '									"touser":"******",' . "\r\n" . '									"msgtype":"text",' . "\r\n" . '									"text":' . "\r\n" . '									{' . "\r\n" . '										 "content":"' . $content . '"' . "\r\n" . '									}' . "\r\n" . '								}';
					$apiOauth->https_request($url, $call);
				}

				break;

			case 'event':
				$content = $data['Event'] . 'from_callback';
				$oauth->response($content);
				break;
			}

			exit();
		}

		if (($this->token == 'pigcms') || ($this->token == 'qcloud')) {
			$qcloudUser = M('Qcloud_user')->where(array('openid' => $_GET['openId']))->find();
			$this->token = $qcloudUser['token'];
		}

		if (!preg_match('/^[0-9a-zA-Z]{3,42}$/', $this->token)) {
			exit('error token');
		}

		if (!$this->ali) {
			$weixin = new Wechat($this->token, $this->wxuser);
		}

		$this->wxuser = S('wxuser_' . $this->token);
		if (!$this->wxuser || 1) {
			$this->wxuser = D('Wxuser')->where(array('token' => $this->token))->find();
			if (C('agent_version') && intval($this->wxuser['agentid'])) {
				$thisAgent = M('Agent')->where(array('id' => $this->wxuser['agentid']))->find();
				$this->siteUrl = $thisAgent['siteurl'];
			}

			S('wxuser_' . $this->token, $this->wxuser);
		}

		$this->user = M('Users')->where(array('id' => $this->wxuser['uid']))->find();

		if (!$this->ali) {
			$data = $weixin->request();
			$this->data = $weixin->request();
		}

		$this->fans = S('fans_' . $this->token . '_' . $this->data['FromUserName']);
		if (!$this->fans || 1) {
			$this->fans = M('Userinfo')->where(array('token' => $this->token, 'wecha_id' => $this->data['FromUserName']))->find();
			S('fans_' . $this->token . '_' . $this->data['FromUserName'], $this->fans);
		}

		$session_openid_name = 'token_openid_' . $this->token;
		$_SESSION[$session_openid_name] = $this->data['FromUserName'];
		$this->my = C('site_my');
		$this->apiServer = apiServer::getServerUrl();
		$open = M('Token_open')->where(array('token' => $this->token))->find();
		$this->fun = $open['queryname'];

		if (!$this->ali) {
			list($content, $type) = $this->reply($data);
			$weixin->response($content, $type);
		}
		else {
			$data = array();
			$data['Content'] = htmlspecialchars($_GET['keyword']);
			$data['FromUserName'] = htmlspecialchars($_GET['fromUserName']);
			$data['FromUserName'] = '******' . md5($data['FromUserName']);
			if (isset($_GET['eventType']) && $_GET['eventType']) {
				$data['Event'] = trim(htmlspecialchars($_GET['eventType']));

				if ($data['Event'] == 'SCAN') {
					$data['EventKey'] = $_GET['EventKey'];
					$eventReplyClassName = 'SCANEventReply';
					class_exists($eventReplyClassName);
					$SCANEventReply = new $eventReplyClassName($this->token, $data['FromUserName'], $data, $this->siteUrl, $this->ali);
					return $SCANEventReply->index();
				}
			}

			$this->data = $data;
			return $this->reply($data);
		}
	}
コード例 #5
0
ファイル: thirdApp.class.php プロジェクト: liuguogen/weixin
 public function huoche($data, $time = '')
 {
     $data = array_merge($data);
     $info = $data[1] . '到' . $data[0] . '的火车';
     $url = apiServer::getApiUrltu() . '?key=' . apiServer::getApiKeyID()['key'] . '&info=' . $info;
     $json = $this->curlGet($url);
     if (empty($json)) {
         return array('哎呀,暂时没找到' . $data[1] . '--' . $data[0] . '的火车~', 'text');
     }
     $datas = json_decode($json, true);
     if ($datas['list']) {
         $str .= "\n【Hi,以下是为您找到列车信息】";
         foreach ($datas['list'] as $lists) {
             $str .= "\n『车次』{$lists['trainnum']}";
             $str .= "\n『起』{$lists['start']} -『终』{$lists['terminal']}";
             $str .= "\n『开』{$lists['starttime']} -『到』{$lists['endtime']}";
             $str .= "\n*****************************";
         }
     } else {
         return array('哎呀,暂时没找到' . $data[1] . '--' . $data[0] . '的火车~', 'text');
     }
     return $str;
 }
コード例 #6
0
ファイル: server.php プロジェクト: rene-hermenau/apiServer
<?php

include dirname(dirname(__FILE__)) . "/class_lib.php";
$server = new apiServer();
$publicKey = $server->getPublicKey();
//
// here the code to retrieve PRIVATEKEY
//
$privateKey = "PRIVATEKEY";
if ($server->handle($privateKey, 123)) {
    //the request can be processed
    $responseCode = array(200, 201, 202, 304);
    $ind = array_rand($responseCode);
    $server->response($responseCode[$ind], "OK");
} else {
    //Error
    $server->response($server->errno);
}
コード例 #7
0
 public function index($ApiData = '')
 {
     if ($ApiData != "") {
         $_GET = $ApiData;
     }
     $this->ali = 0;
     if (isset($_GET["ali"]) && intval($_GET["ali"])) {
         $this->ali = 1;
     }
     $this->siteUrl = C("site_url");
     if (!class_exists("SimpleXMLElement")) {
         exit("SimpleXMLElement class not exist");
     }
     if (!function_exists("dom_import_simplexml")) {
         exit("dom_import_simplexml function not exist");
     }
     if (empty($_GET["token"]) && isset($_GET["appid"])) {
         $appid = ltrim($_GET["appid"], "/");
         $this->token = M("Wxuser")->where("appid='{$appid}'")->getField("token");
     } else {
         $this->token = htmlspecialchars($_GET["token"]);
     }
     if ($appid == "wx570bc396a51b8ff8") {
         $wxarr["type"] = 1;
         $wxarr["encode"] = 2;
         $oauth = new Wechat($appid, $wxarr);
         $apiOauth = new apiOauth();
         $data = $oauth->request();
         $openid = $data["FromUserName"];
         $ToUserName = $data["ToUserName"];
         switch ($data["MsgType"]) {
             case "text":
                 if ($data["Content"] == "TESTCOMPONENT_MSG_TYPE_TEXT") {
                     $content = "TESTCOMPONENT_MSG_TYPE_TEXT_callback";
                     $oauth->response($content);
                 } else {
                     if (strstr($data["Content"], "QUERY_AUTH_CODE")) {
                         $auth_code = str_replace("QUERY_AUTH_CODE:", "", $data["Content"]);
                         $authorization_info = $apiOauth->get_authorization_info($auth_code);
                         $access_token = $authorization_info["authorizer_access_token"];
                         $url = "https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token=" . $access_token;
                         $content = $auth_code . "_from_api";
                         $call = "{\r\n\t\t\t\t\t\t\t\t\t\"touser\":\"" . $openid . "\",\r\n\t\t\t\t\t\t\t\t\t\"msgtype\":\"text\",\r\n\t\t\t\t\t\t\t\t\t\"text\":\r\n\t\t\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\t\t\t \"content\":\"" . $content . "\"\r\n\t\t\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\t\t}";
                         $apiOauth->https_request($url, $call);
                     }
                 }
                 break;
             case "event":
                 $content = $data["Event"] . "from_callback";
                 $oauth->response($content);
                 break;
         }
         exit;
     }
     if ($this->token == "weimicms" || $this->token == "qcloud") {
         $qcloudUser = M("Qcloud_user")->where(array("openid" => $_GET["openId"]))->find();
         $this->token = $qcloudUser["token"];
     }
     if (!preg_match("/^[0-9a-zA-Z]{3,42}\$/", $this->token)) {
         exit("error token");
     }
     if (!$this->ali) {
         $weixin = new Wechat($this->token, $this->wxuser);
     }
     $this->wxuser = S("wxuser_" . $this->token);
     if (!$this->wxuser || 1) {
         $this->wxuser = D("Wxuser")->where(array("token" => $this->token))->find();
         if (C("agent_version") && intval($this->wxuser["agentid"])) {
             $thisAgent = M("Agent")->where(array("id" => $this->wxuser["agentid"]))->find();
             $this->siteUrl = $thisAgent["siteurl"];
         }
         S("wxuser_" . $this->token, $this->wxuser);
     }
     $this->user = M("Users")->where(array("id" => $this->wxuser["uid"]))->find();
     if (!$this->ali) {
         $data = $weixin->request();
         $this->data = $weixin->request();
     }
     $this->mykey = trim(C('server_key'));
     $this->chatkey = trim(C('site_chatkey'));
     $weixin = new Wechat($this->token);
     $data = $weixin->request();
     $this->data = $weixin->request();
     if ($this->data) {
         //自定义机器人名字
         $this->fans = S("fans_" . $this->token . "_" . $this->data["FromUserName"]);
         if (!$this->fans || 1) {
             $this->fans = M("Userinfo")->where(array("token" => $this->token, "wecha_id" => $this->data["FromUserName"]))->find();
             S("fans_" . $this->token . "_" . $this->data["FromUserName"], $this->fans);
         }
         $session_openid_name = "token_openid_" . $this->token;
         $_SESSION[$session_openid_name] = $this->data["FromUserName"];
         $this->my = C("site_my");
         $this->apiServer = apiServer::getServerUrl();
         $open = M("Token_open")->where(array("token" => $this->token))->find();
         $this->fun = $open["queryname"];
         if (!$this->ali) {
             list($content, $type) = $this->reply($data);
             $weixin->response($content, $type);
         } else {
             $data = array();
             $data["Content"] = htmlspecialchars($_GET["keyword"]);
             $data["FromUserName"] = htmlspecialchars($_GET["fromUserName"]);
             $data["FromUserName"] = "******" . md5($data["FromUserName"]);
             if (isset($_GET["eventType"]) && $_GET["eventType"]) {
                 $data["Event"] = trim(htmlspecialchars($_GET["eventType"]));
                 if ($data["Event"] == "SCAN") {
                     $data["EventKey"] = $_GET["EventKey"];
                     $eventReplyClassName = "SCANEventReply";
                     class_exists($eventReplyClassName);
                     $SCANEventReply = new $eventReplyClassName($this->token, $data["FromUserName"], $data, $this->siteUrl, $this->ali);
                     return $SCANEventReply->index();
                 }
             }
             $this->data = $data;
             return $this->reply($data);
         }
     }
 }
コード例 #8
0
ファイル: thirdApp.class.php プロジェクト: kevicki/pig
	public function huoche($data, $time)
	{
		$data = array_merge($data);
		$info = $data[1] . "到" . $data[0] . "的火车";
		$url = apiServer::getApiUrltu() . "?key=" . apiServer::getApiKeyID()["key"] . "&info=" . $info;
		$json = $this->curlGet($url);

		if (empty($json)) {
			return array("哎呀,暂时没找到" . $data[1] . "--" . $data[0] . "的火车~", "text");
		}

		$datas = json_decode($json, true);

		if ($datas["list"]) {
			$str .= "\n【Hi,以下是为您找到列车信息】";

			foreach ($datas["list"] as $lists ) {
				$str .= "\n『车次』{$lists["trainnum"]}";
				$str .= "\n『起』{$lists["start"]} -『终』{$lists["terminal"]}";
				$str .= "\n『开』{$lists["starttime"]} -『到』{$lists["endtime"]}";
				$str .= "\n*****************************";
			}
		}
		else {
			return array("哎呀,暂时没找到" . $data[1] . "--" . $data[0] . "的火车~", "text");
		}

		return $str;
	}