Esempio n. 1
0
	/**
	 * 创建 wx_message_body
	 * @param array $result
	 * @return NULL|WX_Message_Body
	 */
	private static function _createMessageBody($result)
	{
		$messageBody = new WX_Message_Body ();
		$type = @$result['type'] ? $result['type'] : '';
		$messageBody->type = $type;
		$messageBody->to_users = self::$_message->from_user;
		switch ($type) {
			case 'text' :
				if (!@$result['text']) {
					self::$_ERROR = 'text data empty';
					return null;
				}
				$messageBody->content = trim ($result['text']);
				break;
			case 'news' :
				$articles = @$result['news'];
				if(!$articles || !is_array($articles) || count($articles) > 10){
					self::$_ERROR = 'news data error';
					return null;
				}
				foreach ($articles as $key => $value) {
					if (! is_array($value) || ! $value || ! @$value['title'] || ! @$value['description'] || ! @$value['url']
					|| ! @$value['picurl']) {
						self::$_ERROR = 'news param data error';
						return null;
					}
				}
				$messageBody->articles = $articles;
				break;
			case 'music':
				if (! @$result['title'] || ! @$result['description'] || !@$result['music_url']
				|| !@$result['thumb_url'] || !@$result['hq_music_url']) {
					self::$_ERROR = 'music data error';
					return null;
				}
				$messageBody->title = $result['title'];
				$messageBody->description = $result['description'];
				$messageBody->music_url = $result['music_url'];
				$messageBody->thumb_path = $result['thumb_url'];
				$messageBody->hq_music_url = $result['hq_music_url'];
				break;
			case 'voice':
			case 'image':
			case 'video':
				if (! @$result['media_url']) {
					self::$_ERROR = 'media_url error';
					return null;
				}
				$messageBody->attachment = $result['media_url'];
				break;
			default :
				self::$_ERROR = 'message type not exsit';
				return null;
		}

		return $messageBody;
	}
Esempio n. 2
0
	/**
	 * 运行
	 */
	public static function wx()
	{
		SuiShiPHPCPU::run();
	}