Overview

Namespaces

  • None
  • Wei
    • Validator

Classes

  • Apc
  • App
  • ArrayCache
  • Asset
  • Base
  • BaseCache
  • BaseController
  • Bicache
  • Cache
  • Config
  • Cookie
  • Couchbase
  • Counter
  • Db
  • DbCache
  • E
  • Env
  • Error
  • FileCache
  • Gravatar
  • Http
  • Lock
  • Logger
  • Memcache
  • Memcached
  • MongoCache
  • Password
  • PhpError
  • PhpFileCache
  • Pinyin
  • Record
  • Redis
  • Request
  • Response
  • Router
  • SafeUrl
  • Session
  • Soap
  • T
  • Ua
  • Upload
  • Url
  • Uuid
  • Validate
  • View
  • WeChatApp
  • Wei
  • Overview
  • Namespace
  • Class

Class WeChatApp

A service handles WeChat(WeiXin) callback message

Wei\Base
Extended by Wei\WeChatApp
Namespace: Wei
Author: Twin Huang twinhuang@qq.com
Link: http://mp.weixin.qq.com/wiki/index.php?title=%E6%B6%88%E6%81%AF%E6%8E%A5%E5%8F%A3%E6%8C%87%E5%8D%97
Located at WeChatApp.php
Methods summary
public
# __construct( array $options = array() )

Constructor

Constructor

Parameters

$options

Throws

InvalidArgumentException
When option "wei" is not an instance of "Wei\Wei"

Overrides

Wei\Base::__construct()
public
# __invoke( )

Start up WeChat application and output the matched rule message

Start up WeChat application and output the matched rule message

Returns


$this
public string|false
# run( )

Execute the matched rule and returns the rule result

Execute the matched rule and returns the rule result

Returns false when the token is invalid or no rules matched

Returns

string|false
public boolean
# isVerifyToken( )

Check if the request is verify the token string

Check if the request is verify the token string

Returns

boolean
public
# subscribe( Closure $fn )

Attach a callback which triggered when user subscribed you

Attach a callback which triggered when user subscribed you

Parameters

$fn

Returns


$this
public
# unsubscribe( Closure $fn )

Attach a callback which triggered when user unsubscribed you

Attach a callback which triggered when user unsubscribed you

Parameters

$fn

Returns


$this
public
# click( string $key, Closure $fn )

Attach a callback which triggered when user click the custom menu

Attach a callback which triggered when user click the custom menu

Parameters

$key
The key of event
$fn

Returns


$this
public
# scan( Closure $fn )

Attach a callback which triggered when user scan the QR Code

Attach a callback which triggered when user scan the QR Code

Parameters

$fn

Returns


$this
public
# is( string $keyword, Closure $fn )

Attach a callback which triggered when user input equals to the keyword

Attach a callback which triggered when user input equals to the keyword

Parameters

$keyword
The keyword to compare with user input
$fn

Returns


$this
public
# has( string $keyword, Closure $fn )

Attach a callback with a keyword, which triggered when user input contains the keyword

Attach a callback with a keyword, which triggered when user input contains the keyword

Parameters

$keyword
The keyword to search in user input
$fn

Returns


$this
public
# startsWith( string $keyword, Closure $fn )

Attach a callback with a keyword, which triggered when user input starts with the keyword (case insensitive)

Attach a callback with a keyword, which triggered when user input starts with the keyword (case insensitive)

Parameters

$keyword
The keyword to search in user input
$fn

Returns


$this
public
# match( string $pattern, Closure $fn )

Attach a callback with a regex pattern which triggered when user input match the pattern

Attach a callback with a regex pattern which triggered when user input match the pattern

Parameters

$pattern
The pattern to match
$fn

Returns


$this
public
# receiveImage( Closure $fn )

Attach a callback to handle image message

Attach a callback to handle image message

Parameters

$fn

Returns


$this
public
# receiveLocation( Closure $fn )

Attach a callback to handle location message

Attach a callback to handle location message

Parameters

$fn

Returns


$this
public
# receiveVoice( Closure $fn )

Attach a callback to handle voice message

Attach a callback to handle voice message

Parameters

$fn

Returns


$this
public
# receiveVideo( Closure $fn )

Attach a callback to handle video message

Attach a callback to handle video message

Parameters

$fn

Returns


$this
public
# receiveLink( Closure $fn )

Attach a callback to handle link message

Attach a callback to handle link message

Parameters

$fn

Returns


$this
public boolean
# defaults( Closure $fn )

Attach a handler which executes when none of the rule handled the input

Attach a handler which executes when none of the rule handled the input

Parameters

$fn

Returns

boolean
public array
# sendText( string $content )

Generate text message for output

Generate text message for output

Parameters

$content

Returns

array
public array
# sendMusic( string $title, string $description, string $url, string $hqUrl = null )

Generate music message for output

Generate music message for output

Parameters

$title
The title of music
$description
The description display blow the title
$url
The music URL for player
$hqUrl
The HQ music URL for player when user in WIFI

Returns

array
public array
# sendArticle( array $articles )

Generate article message for output

Generate article message for output

// Sends one article
$app->sendArticle(array( 'title' => 'The title of article', 'description' => 'The description of article', 'picUrl' => 'The picture URL of article', 'url' => 'The URL link to of article'
));

// Sends two or more articles
$app->sendArticle(array( array( 'title' => 'The title of article', 'description' => 'The description of article', 'picUrl' => 'The picture URL of article', 'url' => 'The URL link to of article' ), array( 'title' => 'The title of article', 'description' => 'The description of article', 'picUrl' => 'Te picture URL of article', 'url' => 'The URL link to of article' ), // more... ));

Parameters

$articles
The article array

Returns

array
public boolean
# isValid( )

Returns if the token is valid

Returns if the token is valid

Returns

boolean
public mixed
# getAttr( string $name )

Returns the XML element value

Returns the XML element value

Parameters

$name

Returns

mixed
public array
# getAttrs( )

Returns all of XML element values

Returns all of XML element values

Returns

array
public string
# getPostData( )

Returns the HTTP raw post data

Returns the HTTP raw post data

Returns

string
public string
# getToUserName( )

Returns your user id

Returns your user id

Returns

string
public string
# getFromUserName( )

Returns the user openID who sent message to you

Returns the user openID who sent message to you

Returns

string
public string
# getCreateTime( )

Returns the timestamp when message created

Returns the timestamp when message created

Returns

string
public string
# getContent( )

Returns the user input string, available when the message type is text

Returns the user input string, available when the message type is text

Returns

string
public string
# getMsgId( )

Returns the message id

Returns the message id

Returns

string
public string
# getMsgType( )

Returns the message type

Returns the message type

Currently could be text, image, location, link, event, voice, video

Returns

string
public string
# getPicUrl( )

Returns the picture URL, available when the message type is image

Returns the picture URL, available when the message type is image

Returns

string
public string
# getLocationX( )

Returns the latitude of location, available when the message type is location

Returns the latitude of location, available when the message type is location

Returns

string
public string
# getLocationY( )

Returns the longitude of location, available when the message type is location

Returns the longitude of location, available when the message type is location

Returns

string
public string
# getLabel( )

Returns the detail address of location, available when the message type is location

Returns the detail address of location, available when the message type is location

Returns

string
public string
# getScale( )

Returns the scale of map, available when the message type is location

Returns the scale of map, available when the message type is location

Returns

string
public string
# getMediaId( )

Returns the media id, available when the message type is voice or video

Returns the media id, available when the message type is voice or video

Returns

string
public string
# getFormat( )

Returns the media format, available when the message type is voice

Returns the media format, available when the message type is voice

Returns

string
public string
# getEvent( )

Returns the type of event, could be subscribe, unsubscribe or CLICK, available when the message type is event

Returns the type of event, could be subscribe, unsubscribe or CLICK, available when the message type is event

Returns

string
public string
# getEventKey( )

Returns the key value of custom menu, available when the message type is event

Returns the key value of custom menu, available when the message type is event

Returns

string
public string
# getScanSceneId( )

Returns the scene id from the scan result, available when the message event is subscribe or scan

Returns the scene id from the scan result, available when the message event is subscribe or scan

Returns

string
public string
# getThumbMediaId( )

Returns the thumbnail id of video, available when the message type is video

Returns the thumbnail id of video, available when the message type is video

Returns

string
public string
# getTitle( )

Returns the title of URL, available when the message type is link

Returns the title of URL, available when the message type is link

Returns

string
public string
# getDescription( )

Returns the description of URL, available when the message type is link

Returns the description of URL, available when the message type is link

Returns

string
public string
# getUrl( )

Returns the URL link, available when the message type is link

Returns the URL link, available when the message type is link

Returns

string
public string
# getTicket( )

Returns the ticket string, available when user scan from the QR Code

Returns the ticket string, available when user scan from the QR Code

Returns

string
public boolean|string
# getKeyword( )

Returns the user inputted content or clicked button value

Returns the user inputted content or clicked button value

Returns

boolean|string
protected array
# send( string $type, array $response )

Generate message for output

Generate message for output

Parameters

$type
The type of message
$response
The response content

Returns

array
protected
# addTextRule( string $type, string $keyword, Closure $fn )

Adds a rule to handle user text input

Adds a rule to handle user text input

Parameters

$type
$keyword
$fn

Returns


$this
protected
# addEventRule( string $name, string $key, Closure $fn )

Adds a rule to handle user event, such as click, subscribe

Adds a rule to handle user event, such as click, subscribe

Parameters

$name
$key
$fn

Returns


$this
protected
# parsePostData( )

Parse post data to receive user OpenID and input content and message attr

Parse post data to receive user OpenID and input content and message attr

protected string|false
# handleText( )

Handle text rule

Handle text rule

Returns

string|false
protected
# handleEvent( $event, $eventKey = false )
protected string
# handle( Closure $fn )

Executes callback handler

Executes callback handler

Parameters

$fn

Returns

string
protected SimpleXMLElement
# arrayToXml( array $array, SimpleXMLElement $xml = null )

Convert to XML element

Convert to XML element

Parameters

$array
$xml

Returns

SimpleXMLElement
Methods inherited from Wei\Base
__call(), __get(), getOption(), setOption()
Properties summary
protected string $token

The WeChat token to generate signature

The WeChat token to generate signature

# 'wei'
protected string $postData

The HTTP raw post data, equals to $GLOBALS['HTTP_RAW_POST_DATA'] on default

The HTTP raw post data, equals to $GLOBALS['HTTP_RAW_POST_DATA'] on default

#
protected array $query

The URL query parameters, equals to $_GET on default

The URL query parameters, equals to $_GET on default

#
protected array $rules

The rules to generate output message

The rules to generate output message

# array( 'text' => array(), 'event' => array(), 'image' => null, 'location' => null, 'voice' => null, 'video' => null, 'link' => null )
protected callable $defaults

A handler executes when none of rules handled the input

A handler executes when none of rules handled the input

#
protected boolean $valid

Whether the signature is valid

Whether the signature is valid

# false
protected boolean $handled

Are there any callbacks handled the message ?

Are there any callbacks handled the message ?

# false
protected callable $beforeSend

The callback executes before send the XML data

The callback executes before send the XML data

#
protected array $attrs

The element values of post XML data

The element values of post XML data

Most of the available element names in post XML data common : MsgType, FromUserName, ToUserName, MsgId, CreateTime, Ticket text : Content image : PicUrl location: Location_X, Location_Y, Scale, Label voice : MediaId, Format event : Event, EventKey video : MediaId, ThumbMediaId link : Title, Description

# array()
Properties inherited from Wei\Base
$providers, $wei
Wei Framework API documentation generated by ApiGen