1. 程式人生 > >XingeApp 微信推送api 介面

XingeApp 微信推送api 介面

<?php

/*
 * Copyright ? 1998 - 2014 Tencent. All Rights Reserved. 騰訊公司 版權所有
 */

class XingeApp {
	
	const DEVICE_ALL = 0;
	const DEVICE_BROWSER = 1;
	const DEVICE_PC = 2;
	const DEVICE_ANDROID = 3;
	const DEVICE_IOS = 4;
	const DEVICE_WINPHONE = 5;
	
	const IOSENV_PROD = 1;
	const IOSENV_DEV = 2;
	
	public function __construct($accessId, $secretKey)
	{
		assert(isset($accessId) && isset($secretKey));
		
		$this->accessId = $accessId;
		$this->secretKey = $secretKey;
	}
	public function __destruct(){}

	/**
	 * 使用預設設定推送訊息給單個android裝置
	 */
	public static function PushTokenAndroid($accessId, $secretKey, $title, $content, $token)
	{
		$push = new XingeApp($accessId, $secretKey);
		$mess = new Message();
		$mess->setTitle($title);
		$mess->setContent($content);
		$mess->setType(Message::TYPE_NOTIFICATION);
		$mess->setStyle(new Style(0, 1, 1, 1, 0));
		$action = new ClickAction();
		$action->setActionType(ClickAction::TYPE_ACTIVITY);
		$mess->setAction($action);
		$ret = $push->PushSingleDevice($token, $mess);
		return $ret;
	}

	/**
	 * 使用預設設定推送訊息給單個ios裝置
	 */
	public static function PushTokenIos($accessId, $secretKey, $content, $token, $environment)
	{
		$push = new XingeApp($accessId, $secretKey);
		$mess = new MessageIOS();
		$mess->setAlert($content);
		$ret = $push->PushSingleDevice($token, $mess, $environment);
		return $ret;
	}

	/**
	 * 使用預設設定推送訊息給單個android版賬戶
	 */
	public static function PushAccountAndroid($accessId, $secretKey, $title, $content, $account)
	{
		$push = new XingeApp($accessId, $secretKey);
		$mess = new Message();
		$mess->setTitle($title);
		$mess->setContent($content);
		$mess->setType(Message::TYPE_NOTIFICATION);
		$mess->setStyle(new Style(0, 1, 1, 1, 0));
		$action = new ClickAction();
		$action->setActionType(ClickAction::TYPE_ACTIVITY);
		$mess->setAction($action);
		$ret = $push->PushSingleAccount(0, $account, $mess);
		return $ret;
	}

	/**
	 * 使用預設設定推送訊息給單個ios版賬戶
	 */
	public static function PushAccountIos($accessId, $secretKey, $content, $account, $environment)
	{
		$push = new XingeApp($accessId, $secretKey);
		$mess = new MessageIOS();
		$mess->setAlert($content);
		$ret = $push->PushSingleAccount(0, $account, $mess, $environment);
		return $ret;
	}

	/**
	 * 使用預設設定推送訊息給所有裝置android版
	 */
	public static function PushAllAndroid($accessId, $secretKey, $title, $content)
	{
		$push = new XingeApp($accessId, $secretKey);
		$mess = new Message();
		$mess->setTitle($title);
		$mess->setContent($content);
		$mess->setType(Message::TYPE_NOTIFICATION);
		$mess->setStyle(new Style(0, 1, 1, 1, 0));
		$action = new ClickAction();
		$action->setActionType(ClickAction::TYPE_ACTIVITY);
		$mess->setAction($action);
		$ret = $push->PushAllDevices(0, $mess);
		return $ret;
	}

	/**
	 * 使用預設設定推送訊息給所有裝置ios版
	 */
	public static function PushAllIos($accessId, $secretKey, $content, $environment)
	{
		$push = new XingeApp($accessId, $secretKey);
		$mess = new MessageIOS();
		$mess->setAlert($content);
		$ret = $push->PushAllDevices(0, $mess, $environment);
		return $ret;
	}

	/**
	 * 使用預設設定推送訊息給標籤選中裝置android版
	 */
	public static function PushTagAndroid($accessId, $secretKey, $title, $content, $tag)
	{
		$push = new XingeApp($accessId, $secretKey);
		$mess = new Message();
		$mess->setTitle($title);
		$mess->setContent($content);
		$mess->setType(Message::TYPE_NOTIFICATION);
		$mess->setStyle(new Style(0, 1, 1, 1, 0));
		$action = new ClickAction();
		$action->setActionType(ClickAction::TYPE_ACTIVITY);
		$mess->setAction($action);
		$ret = $push->PushTags(0, array(0=>$tag), 'OR', $mess);
		return $ret;
	}

	/**
	 * 使用預設設定推送訊息給標籤選中裝置ios版
	 */
	public static function PushTagIos($accessId, $secretKey, $content, $tag, $environment)
	{
		$push = new XingeApp($accessId, $secretKey);
		$mess = new MessageIOS();
		$mess->setAlert($content);
		$ret = $push->PushTags(0, array(0=>$tag), 'OR', $mess, $environment);
		return $ret;
	}

	/**
	 * 推送訊息給單個裝置
	 */
	public function  PushSingleDevice($deviceToken, $message, $environment=0)
	{
		$ret = array('ret_code'=>-1, 'err_msg'=>'message not valid');

		if (!($message instanceof Message) && !($message instanceof MessageIOS)) return $ret;
		if(!$message->isValid()) return $ret;
		$params = array();
		$params['access_id'] = $this->accessId;
		$params['expire_time'] = $message->getExpireTime();
		$params['send_time'] = $message->getSendTime();
		if($message instanceof Message) $params['multi_pkg'] = $message->getMultiPkg();
		$params['device_token'] = $deviceToken;
		$params['message_type'] = $message->getType();
		$params['message'] = $message->toJson();
		$params['timestamp'] = time();
		$params['environment'] = $environment;
		
		return $this->callRestful(self::RESTAPI_PUSHSINGLEDEVICE, $params);
	}
	
	/**
	 * 推送訊息給單個賬戶
	 */
	public function  PushSingleAccount($deviceType, $account, $message, $environment=0)
	{
		$ret = array('ret_code'=>-1);
		if (!is_int($deviceType) || $deviceType<0 || $deviceType >5) 
		{
			$ret['err_msg'] = 'deviceType not valid';
			return $ret;
		}
		if (!is_string($account) || empty($account))
		{
			$ret['err_msg'] = 'account not valid';
			return $ret;
		}
		if (!($message instanceof Message) && !($message instanceof MessageIOS))
		{
			$ret['err_msg'] = 'message is not android or ios';
			return $ret;
		}
		if($message instanceof MessageIOS)
		{
			if($environment!=XingeApp::IOSENV_DEV && $environment!=XingeApp::IOSENV_PROD)
			{
				$ret['err_msg'] = "ios message environment invalid";
				return $ret;
			}
		}
		if (!$message->isValid())
		{
			$ret['err_msg'] = 'message not valid';
			return $ret;
		}
		$params = array();
		$params['access_id'] = $this->accessId;
		$params['expire_time'] = $message->getExpireTime();
		$params['send_time'] = $message->getSendTime();
		if($message instanceof Message)
			$params['multi_pkg'] = $message->getMultiPkg();
		$params['device_type'] = $deviceType;
		$params['account'] = $account;
		$params['message_type'] = $message->getType();
		$params['message'] = $message->toJson();
		$params['timestamp'] = time();
		$params['environment'] = $environment;

		return $this->callRestful(self::RESTAPI_PUSHSINGLEACCOUNT, $params);
	}
	
	/**
	 * 推送訊息給多個賬戶
	 */
	public function  PushAccountList($deviceType, $accountList, $message, $environment=0)
	{
		$ret = array('ret_code'=>-1);
		if (!is_int($deviceType) || $deviceType<0 || $deviceType >5)
		{
			$ret['err_msg'] = 'deviceType not valid';
			return $ret;
		}
		if (!is_array($accountList) || empty($accountList))
		{
			$ret['err_msg'] = 'accountList not valid';
			return $ret;
		}
		if (!($message instanceof Message) && !($message instanceof MessageIOS))
		{
			$ret['err_msg'] = 'message is not android or ios';
			return $ret;
		}
		if($message instanceof MessageIOS)
		{
			if($environment!=XingeApp::IOSENV_DEV && $environment!=XingeApp::IOSENV_PROD)
			{
				$ret['err_msg'] = "ios message environment invalid";
				return $ret;
			}
		}
		if (!$message->isValid())
		{
			$ret['err_msg'] = 'message not valid';
			return $ret;
		}
		$params = array();
		$params['access_id'] = $this->accessId;
		$params['expire_time'] = $message->getExpireTime();
		if($message instanceof Message)
			$params['multi_pkg'] = $message->getMultiPkg();
		$params['device_type'] = $deviceType;
		$params['account_list'] = json_encode($accountList);
		$params['message_type'] = $message->getType();
		$params['message'] = $message->toJson();
		$params['timestamp'] = time();
		$params['environment'] = $environment;
	
		return $this->callRestful(self::RESTAPI_PUSHACCOUNTLIST, $params);
	}
	
	/**
	 * 推送訊息給APP所有裝置
	 */
	public function  PushAllDevices($deviceType, $message, $environment=0)
	{
		$ret = array('ret_code'=>-1, 'err_msg'=>'message not valid');
		if (!is_int($deviceType) || $deviceType<0 || $deviceType >5)
		{
			$ret['err_msg'] = 'deviceType not valid';
			return $ret;
		}

		if (!($message instanceof Message) && !($message instanceof MessageIOS)) return $ret;
		if(!$message->isValid()) return $ret;
		$params = array();
		$params['access_id'] = $this->accessId;
		$params['expire_time'] = $message->getExpireTime();
		$params['send_time'] = $message->getSendTime();
		if($message instanceof Message) $params['multi_pkg'] = $message->getMultiPkg();
		$params['device_type'] = $deviceType;
		$params['message_type'] = $message->getType();
		$params['message'] = $message->toJson();
		$params['timestamp'] = time();
		$params['environment'] = $environment;

		if (!is_null($message->getLoopInterval()) && $message->getLoopInterval() > 0 
			&& !is_null($message->getLoopTimes()) && $message->getLoopTimes() > 0) {
			$params['loop_interval'] = $message->getLoopInterval();
			$params['loop_times'] = $message->getLoopTimes();
		}
		//var_dump($params);
	
		return $this->callRestful(self::RESTAPI_PUSHALLDEVICE, $params);
	}
	
	/**
	 * 推送訊息給指定tags的裝置
	 * 若要推送的tagList只有一項,則tagsOp應為OR
	 */
	public function  PushTags($deviceType, $tagList, $tagsOp, $message, $environment=0)
	{
		$ret = array('ret_code'=>-1, 'err_msg'=>'message not valid');
		if (!is_int($deviceType) || $deviceType<0 || $deviceType >5) 
		{
			$ret['err_msg'] = 'deviceType not valid';
			return $ret;
		}
		if (!is_array($tagList) || empty($tagList)) 
		{
			$ret['err_msg'] = 'tagList not valid';
			return $ret;
		}
		if (!is_string($tagsOp) || ($tagsOp!='AND' && $tagsOp!='OR')) 
		{
			$ret['err_msg'] = 'tagsOp not valid';
			return $ret;
		}
		
		if (!($message instanceof Message) && !($message instanceof MessageIOS)) return $ret;
		if(!$message->isValid()) return $ret;
		
		$params = array();
		$params['access_id'] = $this->accessId;
		$params['expire_time'] = $message->getExpireTime();
		$params['send_time'] = $message->getSendTime();
		if($message instanceof Message) $params['multi_pkg'] = $message->getMultiPkg();
		$params['device_type'] = $deviceType;
		$params['message_type'] = $message->getType();
		$params['tags_list'] = json_encode($tagList);
		$params['tags_op'] = $tagsOp;
		$params['message'] = $message->toJson();
		$params['timestamp'] = time();
		$params['environment'] = $environment;
		
		if (!is_null($message->getLoopInterval()) && $message->getLoopInterval() > 0 
			&& !is_null($message->getLoopTimes()) && $message->getLoopTimes() > 0) {
			$params['loop_interval'] = $message->getLoopInterval();
			$params['loop_times'] = $message->getLoopTimes();
		}

		return $this->callRestful(self::RESTAPI_PUSHTAGS, $params);
	}

	/**
	 * 建立批量推送任務
	 */
	public function  CreateMultipush($message, $environment=0)
	{
		$ret = array('ret_code'=>-1);
		if (!($message instanceof Message) && !($message instanceof MessageIOS))
		{
			$ret['err_msg'] = 'message is not android or ios';
			return $ret;
		}
		if($message instanceof MessageIOS)
		{
			if($environment!=XingeApp::IOSENV_DEV && $environment!=XingeApp::IOSENV_PROD)
			{
				$ret['err_msg'] = "ios message environment invalid";
				return $ret;
			}
		}
		if (!$message->isValid())
		{
			$ret['err_msg'] = 'message not valid';
			return $ret;
		}
		$params = array();
		$params['access_id'] = $this->accessId;
		$params['expire_time'] = $message->getExpireTime();
		if($message instanceof Message)
			$params['multi_pkg'] = $message->getMultiPkg();
		$params['message_type'] = $message->getType();
		$params['message'] = $message->toJson();
		$params['timestamp'] = time();
		$params['environment'] = $environment;
	
		return $this->callRestful(self::RESTAPI_CREATEMULTIPUSH, $params);
	}
	
	/**
	 * 按帳號大批量推送
	 */
	public function  PushAccountListMultiple($pushId, $accountList)
	{
		$pushId = intval($pushId);
		$ret = array('ret_code'=>-1);
		if ($pushId <= 0)
		{
			$ret['err_msg'] = 'pushId not valid';
			return $ret;
		}
		if (!is_array($accountList) || empty($accountList))
		{
			$ret['err_msg'] = 'accountList not valid';
			return $ret;
		}
		$params = array();
		$params['access_id'] = $this->accessId;
		$params['push_id'] = $pushId;
		$params['account_list'] = json_encode($accountList);
		$params['timestamp'] = time();	

		return $this->callRestful(self::RESTAPI_PUSHACCOUNTLISTMULTIPLE, $params);
	}

	/**
	 * 按Token大批量推送
	 */
	public function  PushDeviceListMultiple($pushId, $deviceList)
	{
		$pushId = intval($pushId);
		$ret = array('ret_code'=>-1);
		if ($pushId <= 0)
		{
			$ret['err_msg'] = 'pushId not valid';
			return $ret;
		}
		if (!is_array($deviceList) || empty($deviceList))
		{
			$ret['err_msg'] = 'deviceList not valid';
			return $ret;
		}
		$params = array();
		$params['access_id'] = $this->accessId;
		$params['push_id'] = $pushId;
		$params['device_list'] = json_encode($deviceList);
		$params['timestamp'] = time();	

		return $this->callRestful(self::RESTAPI_PUSHDEVICELISTMULTIPLE, $params);
	}

	/**
	 * 查詢訊息推送狀態
	 * @param array $pushIdList pushId(string)陣列
	 */
	public function  QueryPushStatus($pushIdList)
	{
		$ret = array('ret_code'=>-1);
		$idList = array();
		if (!is_array($pushIdList) || empty($pushIdList)) 
		{
			$ret['err_msg'] = 'pushIdList not valid';
			return $ret;
		}
		foreach ($pushIdList as $pushId)
		{
			$idList[] = array('push_id'=>$pushId);
		}
		$params = array();
		$params['access_id'] = $this->accessId;
		$params['push_ids'] = json_encode($idList);
		$params['timestamp'] = time();

		return $this->callRestful(self::RESTAPI_QUERYPUSHSTATUS, $params);
	}
	
	/**
	 * 查詢應用覆蓋的裝置數
	 */
	public function  QueryDeviceCount()
	{
		$params = array();
		$params['access_id'] = $this->accessId;
		$params['timestamp'] = time();

		return $this->callRestful(self::RESTAPI_QUERYDEVICECOUNT, $params);
	}
	
	/**
	 * 查詢應用標籤
	 */
	public function  QueryTags($start=0, $limit=100)
	{
		$ret = array('ret_code'=>-1);
		if (!is_int($start) || !is_int($limit))
		{
			$ret['err_msg'] = 'start or limit not valid';
			return $ret;
		}
		$params = array();
		$params['access_id'] = $this->accessId;
		$params['start'] = $start;
		$params['limit'] = $limit;
		$params['timestamp'] = time();
	
		return $this->callRestful(self::RESTAPI_QUERYTAGS, $params);
	}
	
	/**
	 * 查詢標籤下token數量
	 */
	public function  QueryTagTokenNum($tag)
	{
		$ret = array('ret_code'=>-1);
		if (!is_string($tag))
		{
			$ret['err_msg'] = 'tag is not valid';
			return $ret;
		}
		$params = array();
		$params['access_id'] = $this->accessId;
		$params['tag'] = $tag;
		$params['timestamp'] = time();
	
		return $this->callRestful(self::RESTAPI_QUERYTAGTOKENNUM, $params);
	}
	
	/**
	 * 查詢token的標籤
	 */
	public function  QueryTokenTags($deviceToken)
	{
		$ret = array('ret_code'=>-1);
		if (!is_string($deviceToken))
		{
			$ret['err_msg'] = 'deviceToken is not valid';
			return $ret;
		}
		$params = array();
		$params['access_id'] = $this->accessId;
		$params['device_token'] = $deviceToken;
		$params['timestamp'] = time();
	
		return $this->callRestful(self::RESTAPI_QUERYTOKENTAGS, $params);
	}
	
	/**
	 * 取消定時傳送
	 */
	public function  CancelTimingPush($pushId)
	{
		$ret = array('ret_code'=>-1);
		if (!is_string($pushId) || empty($pushId))
		{
			$ret['err_msg'] = 'pushId not valid';
			return $ret;
		}
		$params = array();
		$params['access_id'] = $this->accessId;
		$params['push_id'] = $pushId;
		$params['timestamp'] = time();
	
		return $this->callRestful(self::RESTAPI_CANCELTIMINGPUSH, $params);
	}
	
	//json轉換為陣列
	protected function json2Array($json){
		$json=stripslashes($json);
		return json_decode($json,true);
	}
	
	protected function callRestful($url, $params)
	{
		$paramsBase = new ParamsBase($params);
		$sign = $paramsBase->generateSign(RequestBase::METHOD_POST, $url,  $this->secretKey);
		$params['sign'] = $sign;
		
		$requestBase = new RequestBase();
		$ret = $this->json2Array($requestBase->exec($url, $params, RequestBase::METHOD_POST));
		
		return $ret;
	}

	private function ValidateToken($token)
	{
		if(intval($this->accessId) >= 2200000000) {
            return strlen($token) == 64;
		} else {
            return (strlen($token) == 40 || strlen($token) == 64);
		}
	}

	public function InitParams() {
		
		$params = array();
        $params['access_id'] = $this->accessId;
        $params['timestamp'] = time();

        return $params;
	}    

	public function BatchSetTag($tagTokenPairs) 
	{
		$ret = array('ret_code' => -1);

		foreach ($tagTokenPairs as $pair) {
			if (!($pair instanceof TagTokenPair)) {
				$ret['err_msg'] = 'tag-token pair type error!';
				return $ret;
			}
	        if (!$this->ValidateToken($pair->token)) {
	        	$ret['err_msg'] = sprintf("invalid token %s", $pair->token);
	        	return $ret;
	        }
	    }
	    $params = $this->InitParams();

	    $tag_token_list = array();
	    foreach ($tagTokenPairs as $pair) {
	    	array_push($tag_token_list, array($pair->tag, $pair->token));
	    }
	    $params['tag_token_list'] = json_encode($tag_token_list); 
	   
	   	return $this->callRestful(self::RESTAPI_BATCHSETTAG, $params); 
	}

	public function BatchDelTag($tagTokenPairs) 
	{
		$ret = array('ret_code' => -1);

		foreach ($tagTokenPairs as $pair) {
			if (!($pair instanceof TagTokenPair)) {
				$ret['err_msg'] = 'tag-token pair type error!';
				return $ret;
			}
	        if (!$this->ValidateToken($pair->token)) {
	        	$ret['err_msg'] = sprintf("invalid token %s", $pair->token);
	        	return $ret;
	        }
	    }
	    $params = $this->InitParams();

	    $tag_token_list = array();
	    foreach ($tagTokenPairs as $pair) 	{
	    	array_push($tag_token_list, array($pair->tag, $pair->token));
	    }
	    $params['tag_token_list'] = json_encode($tag_token_list); 
	   
	   	return $this->callRestful(self::RESTAPI_BATCHDELTAG, $params); 
	}
	public function QueryInfoOfToken($deviceToken)
	{
		$ret = array('ret_code'=>-1);
		if (!is_string($deviceToken))
		{
			$ret['err_msg'] = 'deviceToken is not valid';
			return $ret;
		}
		$params = array();
		$params['access_id'] = $this->accessId;
		$params['device_token'] = $deviceToken;
		$params['timestamp'] = time();
	
		return $this->callRestful(self::RESTAPI_QUERYINFOOFTOKEN, $params);
	}
	public function QueryTokensOfAccount($account)
	{
		$ret = array('ret_code'=>-1);
		if (!is_string($account))
		{
			$ret['err_msg'] = 'account is not valid';
			return $ret;
		}
		$params = array();
		$params['access_id'] = $this->accessId;
		$params['account'] = $account;
		$params['timestamp'] = time();
	
		return $this->callRestful(self::RESTAPI_QUERYTOKENSOFACCOUNT, $params);
	}


	public $accessId = ''; //應用的接入Id
	public $secretKey = ''; //應用的skey
	
	const RESTAPI_PUSHSINGLEDEVICE = 'http://openapi.xg.qq.com/v2/push/single_device';
	const RESTAPI_PUSHSINGLEACCOUNT = 'http://openapi.xg.qq.com/v2/push/single_account';
	const RESTAPI_PUSHACCOUNTLIST = 'http://openapi.xg.qq.com/v2/push/account_list';
	const RESTAPI_PUSHALLDEVICE = 'http://openapi.xg.qq.com/v2/push/all_device';
	const RESTAPI_PUSHTAGS = 'http://openapi.xg.qq.com/v2/push/tags_device';
	const RESTAPI_QUERYPUSHSTATUS = 'http://openapi.xg.qq.com/v2/push/get_msg_status';
	const RESTAPI_QUERYDEVICECOUNT = 'http://openapi.xg.qq.com/v2/application/get_app_device_num';
	const RESTAPI_QUERYTAGS = 'http://openapi.xg.qq.com/v2/tags/query_app_tags';
	const RESTAPI_CANCELTIMINGPUSH = 'http://openapi.xg.qq.com/v2/push/cancel_timing_task';
	const RESTAPI_BATCHSETTAG = 'http://openapi.xg.qq.com/v2/tags/batch_set';
	const RESTAPI_BATCHDELTAG = 'http://openapi.xg.qq.com/v2/tags/batch_del';
    const RESTAPI_QUERYTOKENTAGS = 'http://openapi.xg.qq.com/v2/tags/query_token_tags';
    const RESTAPI_QUERYTAGTOKENNUM = 'http://openapi.xg.qq.com/v2/tags/query_tag_token_num';
	const RESTAPI_CREATEMULTIPUSH = 'http://openapi.xg.qq.com/v2/push/create_multipush';
	const RESTAPI_PUSHACCOUNTLISTMULTIPLE = 'http://openapi.xg.qq.com/v2/push/account_list_multiple';
	const RESTAPI_PUSHDEVICELISTMULTIPLE = 'http://openapi.xg.qq.com/v2/push/device_list_multiple';
	const RESTAPI_QUERYINFOOFTOKEN = 'http://openapi.xg.qq.com/v2/application/get_app_token_info';
	const RESTAPI_QUERYTOKENSOFACCOUNT = 'http://openapi.xg.qq.com/v2/application/get_app_account_tokens';
	
}

class TagTokenPair {

	public function __construct($tag, $token)
	{
		$this->tag = strval($tag);
        $this->token = strval($token);
	}
	public function __destruct(){}

	public $tag;
	public $token;
}

class Message {

	public function __construct()
	{
		$this->m_acceptTimes = array();
		$this->m_multiPkg = 0;
		$this->m_raw = "";
		$this->m_style = new Style(0);
		$this->m_action = new ClickAction();
	}
	public function __destruct(){}

	public function setTitle($title)
	{
		$this->m_title = $title;
	}
	public function setContent($content)
	{
		$this->m_content = $content;
	}
	public function setExpireTime($expireTime)
	{
		$this->m_expireTime = $expireTime;
	}
	public function getExpireTime()
	{
		return $this->m_expireTime;
	}
	public function setSendTime($sendTime)
	{
		$this->m_sendTime = $sendTime;
	}
	public function getSendTime()
	{
		return $this->m_sendTime;
	}
	public function addAcceptTime($acceptTime)
	{
		$this->m_acceptTimes[] = $acceptTime;
	}
	public function acceptTimeToJson()
	{
		$ret = array();
		foreach ($this->m_acceptTimes as $acceptTime)
		{
			$ret[] = $acceptTime->toArray();
		}
		return $ret;
	}
	/**
	 * 訊息型別
	 * @param int $type 1:通知 2:透傳訊息
	 */
	public function setType($type)
	{
		$this->m_type = $type;
	}
	public function getType()
	{
		return $this->m_type;
	}
	public function setMultiPkg($multiPkg)
	{
		$this->m_multiPkg = $multiPkg;
	}
	public function getMultiPkg()
	{
		return $this->m_multiPkg;
	}
	public function setStyle($style)
	{
		$this->m_style = $style;
	}
	public function setAction($action)
	{
		$this->m_action = $action;
	}
	public function setCustom($custom)
	{
		$this->m_custom = $custom;
	}
	public function setRaw($raw)
	{
		$this->m_raw = $raw;
	}
	public function getLoopInterval() 
	{
		return $this->m_loopInterval;
	}
	public function setLoopInterval($loopInterval) 
	{
		$this->m_loopInterval = $loopInterval;
	}
	public function getLoopTimes() 
	{
		return $this->m_loopTimes;
	}
	public function setLoopTimes($loopTimes) 
	{
		$this->m_loopTimes = $loopTimes;
	}

	public function toJson()
	{
		if(!empty($this->m_raw)) return $this->m_raw;
		$ret = array();
		if ($this->m_type == self::TYPE_NOTIFICATION)
		{
			$ret['title'] = $this->m_title;
			$ret['content'] = $this->m_content;
			$ret['accept_time'] = $this->acceptTimeToJson();
			$ret['builder_id'] = $this->m_style->getBuilderId();
			$ret['ring'] = $this->m_style->getRing();
			$ret['vibrate'] = $this->m_style->getVibrate();
			$ret['clearable'] = $this->m_style->getClearable();
			$ret['n_id'] = $this->m_style->getNId();

			if (!is_null($this->m_style->getRingRaw())) {
				$ret['ring_raw'] = $this->m_style->getRingRaw();
			}
			$ret['lights'] = $this->m_style->getLights();
			$ret['icon_type'] = $this->m_style->getIconType();
			if (!is_null($this->m_style->getIconRes())) {
				$ret['icon_res'] = $this->m_style->getIconRes();
			}
			$ret['style_id'] = $this->m_style->getStyleId();
			if (!is_null($this->m_style->getSmallIcon())) {
				$ret['small_icon'] = $this->m_style->getSmallIcon();
			}
			
			$ret['action'] = $this->m_action->toJson();

		}
		else if($this->m_type == self::TYPE_MESSAGE)
		{
			$ret['title'] = $this->m_title;
			$ret['content'] = $this->m_content;
			$ret['accept_time'] = $this->acceptTimeToJson();
		}
		$ret['custom_content'] = $this->m_custom;
		return json_encode($ret);
	}

	public function isValid()
	{
		if (is_string($this->m_raw) && !empty($this->raw)) return true;
		if(!isset($this->m_title))
			$this->m_title = "";
		else if(!is_string($this->m_title) || empty($this->m_title)) 
			return false;
		if(!isset($this->m_content))
			$this->m_content = "";
		else if(!is_string($this->m_content) || empty($this->m_content)) 
			return false;
		if(!is_int($this->m_type) || $this->m_type<self::TYPE_NOTIFICATION || $this->m_type>self::TYPE_MESSAGE) return false;
		if(!is_int($this->m_multiPkg) || $this->m_multiPkg<0 || $this->m_multiPkg>1) return false;
		if($this->m_type == self::TYPE_NOTIFICATION)
		{
			if(!($this->m_style instanceof Style) || !($this->m_action instanceof ClickAction))
				return false;
			if(!$this->m_style->isValid() || !$this->m_action->isValid())
				return false;
		}
		if (isset($this->m_expireTime))
		{
			if(!is_int($this->m_expireTime) || $this->m_expireTime>3*24*60*60)
				return false;
		}
		else
		{
			$this->m_expireTime = 0;
		}

		if(isset($this->m_sendTime))
		{
			if(strtotime($this->m_sendTime)===false) return false;
		}
		else
		{
			$this->m_sendTime = "2013-12-19 17:49:00";
		}

		foreach ($this->m_acceptTimes as $value)
		{
			if(!($value instanceof TimeInterval) || !$value->isValid())
				return false;
		}

		if(isset($this->m_custom))
		{
			if(!is_array($this->m_custom))
				return false;
		}
		else
		{
			$this->m_custom = array();
		}

		if(isset($this->m_loopInterval)) {
			if(!(is_int($this->m_loopInterval) && $this->m_loopInterval > 0)) {
				return false;
			}	
		}

		if(isset($this->m_loopTimes)) {
			if(!(is_int($this->m_loopTimes) && $this->m_loopTimes > 0)) {
				return false;
			}	
		}

		if(isset($this->m_loopInterval) && isset($this->m_loopTimes)) {
			if(($this->m_loopTimes - 1) * $this->m_loopInterval + 1 > self::MAX_LOOP_TASK_DAYS) {
				return false;
			}
		}

		return true;
	}

	private $m_title;
	private $m_content;
	private $m_expireTime;
	private $m_sendTime;
	private $m_acceptTimes;
	private $m_type;
	private $m_multiPkg;
	private $m_style;
	private $m_action;
	private $m_custom;
	private $m_raw;
	private $m_loopInterval;
	private $m_loopTimes;
	
	const TYPE_NOTIFICATION  = 1;
	const TYPE_MESSAGE = 2;
	const MAX_LOOP_TASK_DAYS = 15;
}

class MessageIOS
{
	public function __construct()
	{
		$this->m_acceptTimes = array();
	}
	public function __destruct(){}

	public function setExpireTime($expireTime)
	{
		$this->m_expireTime = $expireTime;
	}
	public function getExpireTime()
	{
		return $this->m_expireTime;
	}
	public function setSendTime($sendTime)
	{
		$this->m_sendTime = $sendTime;
	}
	public function getSendTime()
	{
		return $this->m_sendTime;
	}
	public function addAcceptTime($acceptTime)
	{
		$this->m_acceptTimes[] = $acceptTime;
	}
	public function acceptTimeToJson()
	{
		$ret = array();
		foreach ($this->m_acceptTimes as $acceptTime)
		{
			$ret[] = $acceptTime->toArray();
		}
		return $ret;
	}
	public function setCustom($custom)
	{
		$this->m_custom = $custom;
	}
	public function setRaw($raw)
	{
		$this->m_raw = $raw;
	}
	public function setAlert($alert)
	{
		$this->m_alert = $alert;
	}
	public function setBadge($badge)
	{
		$this->m_badge = $badge;
	}
	public function setSound($sound)
	{
		$this->m_sound = $sound;
	}
	public function getType()
	{
		return 0;
	}
	public function getCategory()
	{
		return $this->m_category;
	}
	public function setCategory($category)
	{
		$this->m_category = $category;
	}
	public function getLoopInterval() 
	{
		return $this->m_loopInterval;
	}
	public function setLoopInterval($loopInterval) 
	{
		$this->m_loopInterval = $loopInterval;
	}
	public function getLoopTimes() 
	{
		return $this->m_loopTimes;
	}
	public function setLoopTimes($loopTimes) 
	{
		$this->m_loopTimes = $loopTimes;
	}

	public function toJson()
	{
		if(!empty($this->m_raw)) return $this->m_raw;
		$ret = $this->m_custom;
		$aps = array();
		$ret['accept_time'] = $this->acceptTimeToJson();
		$aps['alert'] = $this->m_alert;
		if(isset($this->m_badge)) $aps['badge'] = $this->m_badge;
		if(isset($this->m_sound))$aps['sound'] = $this->m_sound;
		if(isset($this->m_category))$aps['category'] = $this->m_category;
		$ret['aps'] = $aps;
		return json_encode($ret);
	}
	
	public function isValid()
	{
		if (is_string($this->m_raw) && !empty($this->raw)) return true;
		if (isset($this->m_expireTime))
		{
			if(!is_int($this->m_expireTime) || $this->m_expireTime>3*24*60*60)
				return false;
		}
		else
		{
			$this->m_expireTime = 0;
		}
	
		if(isset($this->m_sendTime))
		{
			if(strtotime($this->m_sendTime)===false) return false;
		}
		else
		{
			$this->m_sendTime = "2014-03-13 12:00:00";
		}
	
		foreach ($this->m_acceptTimes as $value)
		{
			if(!($value instanceof TimeInterval) || !$value->isValid())
				return false;
		}
	
		if(isset($this->m_custom))
		{
			if(!is_array($this->m_custom))
				return false;
		}
		else
		{
			$this->m_custom = array();
		}
		if(!isset($this->m_alert)) return false;
		if(!is_string($this->m_alert) && !is_array($this->m_alert))
			return false;
		if(isset($this->m_badge))
		{
			if (!is_int($this->m_badge))
				return false;
		}
		if(isset($this->m_sound))
		{
			if (!is_string($this->m_sound))
				return false;
		}
		if(isset($this->m_loopInterval)) {
			if(!(is_int($this->m_loopInterval) && $this->m_loopInterval > 0)) {
				return false;
			}	
		}
		if(isset($this->m_loopTimes)) {
			if(!(is_int($this->m_loopTimes) && $this->m_loopTimes > 0)) {
				return false;
			}	
		}
		if(isset($this->m_loopInterval) && isset($this->m_loopTimes)) {
			if(($this->m_loopTimes - 1) * $this->m_loopInterval + 1 > self::MAX_LOOP_TASK_DAYS) {
				return false;
			}
		}
	
		return true;
	}
	
	
	private $m_expireTime;
	private $m_sendTime;
	private $m_acceptTimes;
	private $m_custom;
	private $m_raw;
	private $m_alert;
	private $m_badge;
	private $m_sound;
	private $m_category;
	private $m_loopInterval;
	private $m_loopTimes;

	const MAX_LOOP_TASK_DAYS = 15;
}

class ClickAction {
	/**
	 * 動作型別
	 * @param int $actionType 1開啟activity或app本身,2開啟url,3開啟Intent
	 */
	public function __construct()
	{
		$this->m_atyAttrIntentFlag = 0;
		$this->m_atyAttrPendingIntentFlag = 0;
		$this->m_confirmOnPackageDownloadUrl = 1;
	}

	public function setActionType($actionType) {
		$this->m_actionType = $actionType;
	}

	public function setUrl($url) {
		$this->m_url = $url;
	}

	public function setComfirmOnUrl($comfirmOnUrl) {
		$this->m_confirmOnUrl = $comfirmOnUrl;
	}

	public function setActivity($activity) {
		$this->m_activity = $activity;
	}

	public function setIntent($intent) {
		$this->m_intent = $intent;
	}

	public function setAtyAttrIntentFlag($atyAttrIntentFlag) {
		$this->m_atyAttrIntentFlag = $atyAttrIntentFlag;
	}

	public function setAtyAttrPendingIntentFlag($atyAttrPendingIntentFlag) {
		$this->m_atyAttrPendingIntentFlag = $atyAttrPendingIntentFlag;
	}

	public function setPackageDownloadUrl($packageDownloadUrl) {
		$this->m_packageDownloadUrl = $packageDownloadUrl;
	}

	public function setConfirmOnPackageDownloadUrl($confirmOnPackageDownloadUrl) {
		$this->m_confirmOnPackageDownloadUrl = $confirmOnPackageDownloadUrl;
	}

	public function setPackageName($packageName) {
		$this->m_packageName = $packageName;
	}

	public function toJson()
	{
		$ret = array();
		$ret['action_type'] = $this->m_actionType;
		$ret['browser'] = array('url'=>$this->m_url, 'confirm'=>$this->m_confirmOnUrl);
		$ret['activity'] = $this->m_activity;
		$ret['intent'] = $this->m_intent;

		$aty_attr = array();
		if (isset($this->m_atyAttrIntentFlag)) {
			$aty_attr['if'] = $this->m_atyAttrIntentFlag;
		}
		if (isset($this->m_atyAttrPendingIntentFlag)) {
			$aty_attr['pf'] = $this->m_atyAttrPendingIntentFlag;
		}
		$ret['aty_attr'] = $aty_attr;

		return $ret;
	}

	public function isValid()
	{
		if (!isset($this->m_actionType)) $this->m_actionType = self::TYPE_ACTIVITY;
		if (!is_int($this->m_actionType)) return false;
		if ($this->m_actionType<self::TYPE_ACTIVITY || $this->m_actionType>self::TYPE_INTENT)
			return false;

		if($this->m_actionType == self::TYPE_ACTIVITY)
		{
			if (!isset($this->m_activity))
			{
				$this->m_activity = "";
				return true;
			}
			if (isset($this->m_atyAttrIntentFlag)) 
			{
				if (!is_int($this->m_atyAttrIntentFlag)) {
					return false;
				}
			}
			if (isset($this->m_atyAttrPendingIntentFlag)) 
			{
				if (!is_int($this->m_atyAttrPendingIntentFlag)) {
					return false;
				}
			}

			if (is_string($this->m_activity) && !empty($this->m_activity))
				return true;
			return false;
		}

		if($this->m_actionType == self::TYPE_URL)
		{
			if (is_string($this->m_url) && !empty($this->m_url) &&
			is_int($this->m_confirmOnUrl) &&
			$this->m_confirmOnUrl>=0 && $this->m_confirmOnUrl<=1
			)
				return true;
			return false;
		}

		if($this->m_actionType == self::TYPE_INTENT)
		{
			if (is_string($this->m_intent) && !empty($this->m_intent))
				return true;
			return false;
		}	
	}

	private $m_actionType;
	private $m_url;
	private $m_confirmOnUrl;
	private $m_activity;
	private $m_intent;
	private $m_atyAttrIntentFlag;
	private $m_atyAttrPendingIntentFlag;
	private $m_packageDownloadUrl;
	private $m_confirmOnPackageDownloadUrl;
	private $m_packageName;
	
	const TYPE_ACTIVITY = 1;
	const TYPE_URL = 2;
	const TYPE_INTENT = 3;
}

class Style {
	public function __construct($builderId, $ring=0, $vibrate=0, $clearable=1, $nId=0, $lights=1, $iconType=0, $styleId=1)
	{
		$this->m_builderId = $builderId;
		$this->m_ring = $ring;
		$this->m_vibrate = $vibrate;
		$this->m_clearable = $clearable;
		$this->m_nId = $nId;
		$this->m_lights = $lights;
		$this->m_iconType = $iconType;
		$this->m_styleId = $styleId;
	}
	public  function __destruct(){}

	public function getBuilderId()
	{
		return $this->m_builderId;
	}

	public function getRing()
	{
		return $this->m_ring;
	}

	public function getVibrate()
	{
		return $this->m_vibrate;
	}

	public function getClearable()
	{
		return $this->m_clearable;
	}
	
	public function getNId()
	{
		return $this->m_nId;
	}

	public function getLights()
	{
		return $this->m_lights;
	}

	public function getIconType()
	{
		return $this->m_iconType;
	}

	public function getStyleId()
	{
		return $this->m_styleId;
	}

	public function setRingRaw($ringRaw)
	{
		return $this->m_ringRaw = $ringRaw;
	}

	public function getRingRaw()
	{
		return $this->m_ringRaw;
	}

	public function setIconRes($iconRes)
	{
		return $this->m_iconRes = $iconRes;
	}

	public function getIconRes() {
		return $this->m_iconRes;
	}

	public function setSmallIcon($smallIcon)
	{
		return $this->m_smallIcon = $smallIcon;
	}	

	public function getSmallIcon()
	{
		return $this->m_smallIcon;
	}

	public function isValid()
	{
		if (!is_int($this->m_builderId) || !is_int($this->m_ring) ||
			!is_int($this->m_vibrate) || !is_int($this->m_clearable) ||
			!is_int($this->m_lights) || !is_int($this->m_iconType) ||
			!is_int($this->m_styleId)
		)
			return false;
		if ($this->m_ring<0 || $this->m_ring>1) return false;
		if ($this->m_vibrate<0 || $this->m_vibrate>1) return false;
		if ($this->m_clearable<0 || $this->m_clearable>1) return false;
		if ($this->m_lights<0 || $this->m_lights>1) return false;
		if ($this->m_iconType<0 || $this->m_iconType>1) return false;
		if ($this->m_styleId<0 || $this->m_styleId>1) return false;

		return true;
	}

	private $m_builderId;
	private $m_ring;
	private $m_vibrate;
	private $m_clearable;
	private $m_nId;
	private $m_ringRaw;
	private $m_lights;
	private $m_iconType;
	private $m_iconRes;
	private $m_styleId;
	private $m_smallIcon;
}

class TimeInterval
{
	public function __construct($startHour, $startMin, $endHour, $endMin)
	{
		$this->m_startHour = $startHour;
		$this->m_startMin = $startMin;
		$this->m_endHour = $endHour;
		$this->m_endMin = $endMin;
	}
	public  function __destruct(){}
	public function toArray()
	{
		return  array(
				'start' => array('hour'=>strval($this->m_startHour), 'min'=>strval($this->m_startMin)),
				'end'   => array('hour'=>strval($this->m_endHour), 'min'=>strval($this->m_endMin))
		);
	}
	public function isValid()
	{
		if (!is_int($this->m_startHour) || !is_int($this->m_startMin) ||
		!is_int($this->m_endHour) || !is_int($this->m_endMin)
		)
			return false;

		if ($this->m_startHour>=0 && $this->m_startHour<=23 &&
		$this->m_startMin>=0 && $this->m_startMin<=59 &&
		$this->m_endHour>=0 && $this->m_endHour<=23 &&
		$this->m_endMin>=0 && $this->m_endMin<=59
		)
			return true;
		else
			return false;
	}
	private $m_startHour;
	private $m_startMin;
	private $m_endHour;
	private $m_endMin;
}

class ParamsBase
{

	/**
	 * @var array 當前傳入的引數列表
	 */
	public $_params = array();

	/**
	 * 建構函式
	*/
	public function __construct($params)
	{
		if(!is_array($params)){
			return array();
		}
		foreach ($params as $key => $value) {
			//如果是非法的key值,則不使用這個key
			$this->_params[$key] = $value;
		}
	}

	public function set($k, $v){
		if(!isset($k) || !isset($v)){
			return;
		}
		$this->_params[$k] = $v;
	}

	/**
	 * 根據例項化傳入的引數生成簽名
	 */
	public function generateSign($method, $url, $secret_key)
	{
		//將引數進行升序排序
		$param_str = '';
		$method = strtoupper($method);
		$url_arr = parse_url($url);
		if(isset($url_arr['host']) && isset($url_arr['path'])){
			$url = $url_arr['host'].$url_arr['path'];
		}
		if(!empty($this->_params)){
			ksort($this->_params);
			foreach ($this->_params as $key => $value) {
				$param_str.=$key.'='.$value;
			}
		}
		//print $method.$url.$param_str.$secret_key."\n";
		return md5($method.$url.$param_str.$secret_key);
	}

}

class RequestBase{

	//get請求方式
	const METHOD_GET  = 'get';
	//post請求方式
	const METHOD_POST = 'post';

	/**
	 * 發起一個get或post請求
	 * @param $url 請求的url
	 * @param int $method 請求方式
	 * @param array $params 請求引數
	 * @param array $extra_conf curl配置, 高階需求可以用, 如
	 * $extra_conf = array(
	 *    CURLOPT_HEADER => true,
	 *    CURLOPT_RETURNTRANSFER = false
	 * )
	 * @return bool|mixed 成功返回資料,失敗返回false
	 * @throws Exception
	 */
	public static function exec($url,  $params = array(), $method = self::METHOD_GET, $extra_conf = array())
	{
        set_time_limit(60);
		$params = is_array($params)? http_build_query($params): $params;
		//如果是get請求,直接將引數附在url後面
		if($method == self::METHOD_GET)
		{
			$url .= (strpos($url, '?') === false ? '?':'&') . $params;
		}

		//預設配置
		$curl_conf = array(
				CURLOPT_URL => $url,  //請求url
				CURLOPT_HEADER => false,  //不輸出頭資訊
				CURLOPT_RETURNTRANSFER => true, //不輸出返回資料
				CURLOPT_CONNECTTIMEOUT => 10 // 連線超時時間
		);

		//配置post請求額外需要的配置項
		if($method == self::METHOD_POST)
		{
			//使用post方式
			$curl_conf[CURLOPT_POST] = true;
			//post引數
			$curl_conf[CURLOPT_POSTFIELDS] = $params;
		}

		//新增額外的配置
		foreach($extra_conf as $k => $v)
		{
			$curl_conf[$k] = $v;
		}

		$data = false;
		try
		{
			//初始化一個curl控制代碼
			$curl_handle = curl_init();
			//設定curl的配置項
			curl_setopt_array($curl_handle, $curl_conf);
			//發起請求
			$data = curl_exec($curl_handle);
			if($data === false)
			{
				throw new Exception('CURL ERROR: ' . curl_error($curl_handle));
			}
		}
		catch(Exception $e)
		{
			echo $e->getMessage();
		}
		curl_close($curl_handle);

		return $data;
	}
}



?>

相關推薦

XingeApp api 介面

<?php /* * Copyright ? 1998 - 2014 Tencent. All Rights Reserved. 騰訊公司 版權所有 */ class XingeApp { const DEVICE_ALL = 0; const DEV

模板資訊介面(乾貨-程式碼)

這裡僅針對推送模板資訊進行程式碼整理~~~ 本文分為以下三個部分: 一、申請模板訊息許可權 二、開發模板訊息SDK 三、JAVA程式碼實現傳送模板訊息 一、申請模板訊息許可權 模板訊息的申請需微信公眾賬號已經認證通過。 在微信公眾平

模板訊息測試

1.通過appid、secret換access_token https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=appid&secret=secret 2.通過access_to

企業訊息

首先我們需要先看API知道推送的需要的步驟 企業微信的官方開放的API地址:https://work.weixin.qq.com/api/doc 推送企業微信訊息分為這麼幾步: 1、建立企業應用,只能給應用裡面的成員傳送訊息 2、獲取accss_token,這是通過企

day93之

python之微信推送詳解 用什麼推送    -郵件    -微信推送    -簡訊推送微信推送   -公眾號(不能主動給使用者發訊息)     -認證的公眾號:需要營業執照,需要交錢,可以發多篇文

Django -

目錄 一、微信公眾號分類 1-1 公眾號 - 不能主動傳送資訊 1-2 服務號 - 用於微信推送 1-3 企業號 - 企業內部使用 二、微信推送Demo 官方API文件  2-1 測試微信公眾號關注使用者列表 2-2 使用者表結構設計 2-3 實現

解密域名檢測API介面實現原理

最近在網上看到很多網友在問微信域名攔截檢測API介面。有的是想找一個穩定靠譜的服務商,有的是剛接觸這方面的業務想通過程式來代替之前的人工檢測,更有甚者想具體瞭解微信域名檢測API介面的原理,當然這部分人群大多數是技術人員或者是喜歡研究的。不管你是出於什麼目的,作為一個研究介面服務多年的人來說這個介面的原理是非

域名檢測API介面猴子資料使用教程

大家在微信中瀏覽連結的時候一定會出現“已停止訪問該網頁”這種情況,這種情況表示推廣的域名已經被微信瀏覽器攔截(遮蔽)。   這是微信為營造和維護好的網路環境針對誘導分享,不健康內容等連結進行的限制。這對於專門做微信推廣和微信營銷的朋友們來說是個致命打擊,每天花錢花人力物力去推廣,哪知道還沒到

DAY108 - 路飛學城(四)- 路飛學城之支付寶支付、

一、支付寶支付 正式環境: ​ 用營業執照,申請商戶號,appid 測試環境: ​ 沙箱環境:https://openhome.alipay.com/platform/appDaily.htm?tab=info 第一步 # 呼叫AliPay介面 from utils.pay import AliP

PHP實現模板訊息

原文:https://blog.csdn.net/haoyunyun888/article/details/85857638  版權宣告:本文為博主原創文章,轉載請附上博文連結! 案例效果: 應用場景: 模板通知應用場景: 1.撕名牌通知 2.組織人員通知 3.Wp

公眾平臺API介面開發教程

簡介 微信公眾平臺訊息介面為開發者提供了一種新的訊息處理方式。微信公眾平臺訊息介面為開發者提供與使用者進行訊息互動的能力。對於成功接入訊息介面的微信公眾賬號,當用戶發訊息給公眾號,微信公眾平臺伺服器會使用http請求對接入的網址進行訊息推送,第三方伺服器可通過響應包回覆特

php公眾平臺API介面(thinkphp5)

整合了微信公眾號的介面。包括但不限於:獲取access_token,自定義選單,訊息管理,使用者管理等。持續更新。。。下一步增加微信支付和支付寶支付介面 介面類使用了名稱空間,可直接引入並例項化。基於thinkphp5測試。 介面類放在extend/We

短消息

all 得到 ESS 二維 acc 服務號 pan 獲取用戶基本信息 實現 推送短消息:按照級別由低到高>> 公眾號---->已認證公眾號----->服務號----->已認證服務號------>企業號 前提:基於微信認證服務號 主動推送微

java獲取公總號的所有資訊的url,用於爬取的文章內容

場景描述:    在使用者提出需要爬取微信公總號推送訊息的時候,感覺是懵逼的,之前從來沒爬取過,無從下手,沒辦法顧客是上帝,既然使用者提出了需求,我們只能想法去解決問題。    然後根據使用者提供微信公總號  安泰科現貨報價 去爬取,發現公總號推送的訊息的url並不是固定不變

免註冊公眾號的三種訊息服務的C#程式碼實現

【溫馨提示】 本文共1678字,3張圖。預計閱讀時間需要5分鐘。   有時候我們需要監控一些網路上的變化,但是每次去重新整理網頁卻又很麻煩,而且大部分重新整理的時候網頁並沒有更新。那麼有沒有一個工具,可以監控網頁變化,並將變化的結果推送到手機微信上呢? 這裡有很多應用場景,比如前一段時間很

接入WxPusher服務出現錯誤:Content type 'application/x-www-form-urlencoded;charset=UTF-8' not supported

# 背景 使用WxPusher微信推送服務 ,可以及時的將服務的一些執行異常資訊,傳送到自己的微信上,方便了解服務的執行狀態(PS:這個服務是免費的)。 你可以在這裡看到WxPusher微信推送服務的接入說明文件:[https://wxpusher.zjiecode.com/docs/](https://w

使用WxPusher給自己的個人傳送提醒訊息(WxPusher服務)

# 1、背景 我們很多時候,我們在伺服器上執行軟體,發生一些業務異常,需要給我們傳送一個及時的提醒,或者是使用一些耗時軟體,比如搶車票,搶課,刷優惠券當任務執行成功以後,也需要及時的傳送訊息給自己 ,告訴這個狀態。可選用的方案有:簡訊、郵件等,簡訊接入複雜,並且需要付費 ;郵件接入也不簡單,而且接收可能不及時

呼叫企業應用api訊息(spingboot)

//推送訊息 public static String sendMessage(){ //String token =getAccessToken(); String token ="6qK5a5k07UXGDt6jt5KAmn5jhaU-G

公眾平臺訊息介面開發(24)圖片識別之人臉識別API

一、微信圖片獲取 首先要獲得使用者發過來的圖片,微信公眾平臺支援接收圖片,一條圖片訊息的格式如下: <xml> <ToUserName><![CDATA[gh_13d1a3a7x46a]]></ToUserName>

模板消息

ews sls server url main web 根據 utf-8 javax 模板消息僅用於公眾號向用戶發送重要的服務通知,只能用於符合其要求的服務場景中,如信用卡刷卡通知,商品購買成功通知等。不支持廣告等營銷類消息以及其它所有可能對用戶造成騷擾的消息。 關於使