WeChat API Documentation

BaseReq

public

Base class of all request classes of WeChat SDK.

Import WXApiObject.h; BaseReq

property
(int) type
int BaseReq::type

Request type

(NSString *) openID
NSString* BaseReq::openID

The unique identifier, comprised of a user’s WeChat ID and App ID, must be filled by developers while sending a request. The purpose is to check whether the user has logged in with another account.

BaseResp

public

Base class of all response classes of WeChat SDK.

Import WXApiObject.h; BaseResp

property
(int) errCode
int BaseResp::errCode

Error code

(NSString *) errStr
NSString* BaseResp::errStr

Error notification string

(int) type
int BaseResp::type

Response type

GetMessageFromWXReq

public

Message structure that the third-party application uses to request authorization from WeChat.

Import WXApiObject.h; GetMessageFromWXReq

The third-party app requests for verification and authorization by calling sendReq member function of WXApi. WeChat will return a result after processing.

GetMessageFromWXResp

public

Message structure that the third-party application uses to response requests from WeChat.

Import WXApiObject.h; GetMessageFromWXResp

WeChat sends a request to a third-party application; and the third-party application calls sendResp to return the result in a GetMessageFromWXResp message.

property
(NSString *) text
NSString* GetMessageFromWXResp::text

Text contents provided to WeChat

(WXMediaMessage *) message
WXMediaMessage* GetMessageFromWXResp::message

Multi-media contents provided to WeChat

(BOOL) bText
BOOL GetMessageFromWXResp::bText

Types of message that providing contents to WeChat. It could be text or multi-media but not both.

LaunchFromWXReq

public

The message structure carried by WeChat client when a third-party application is opened.

Import WXApiObject.h; LaunchFromWXReq

This is the WeChat’s data structure sent to a third party. No return value expected from the third party.

SendMessageToWXReq

public

Message structure that the third-party application uses to send message to WeChat.

Import WXApiObject.h; SendMessageToWXReq

The third-party app uses SendMessageToWXReq to send messages to WeChat. The message type can be text (member: text) and multi-media (member: message). WeChat will then return the result after processing.

property
(NSString *) text
NSString* SendMessageToWXReq::text

Text contents in the message sent

(WXMediaMessage *) message
WXMediaMessage* SendMessageToWXReq::message

Multi-media contents in the message sent

(BOOL) bText
BOOL SendMessageToWXReq::bText

The message type can be Text or Multi-media but not both.

(int) scene
int SendMessageToWXReq::scene

Target scene, you can send to contact or moments. Contact if default choice.

SendMessageToWXResp

public

Result of SendMessageToWXReq that WeChat returns to the third-party app.

Import WXApiObject.h; SendMessageToWXResp

Wechat uses SendMessageToWXResp to return results of SendMessageToWXReq from the third-party app.

ShowMessageFromWXReq

public

WeChat asks the third-party to show contents.

Import WXApiObject.h; ShowMessageFromWXReq

WeChat sends an ShowMessageFromWXReq message to ask the third-party app to show certain contents. And the third-party app calls sendResp to send an ShowMessageFromWXResp message to WeChat after processing.

property
(WXMediaMessage *) message
WXMediaMessage* ShowMessageFromWXReq::message

WeChat asks the third-party to show contents

ShowMessageFromWXResp

public

WeChat sends an ShowMessageFromWXReq message to ask the third-party app to show certain contents. And the third-party app calls sendResp to send an ShowMessageFromWXResp message to WeChat after processing.

Import WXApiObject.h; ShowMessageFromWXResp

WXApi

public

WeChat API interface functions.

Import WXApi.h; WXApi

This class envelopes all interfaces of WeChat SDK

function
(BOOL) registerApp

Member function of WXApi. It's used to register the third-party app in WeChat.

BOOL WXApi::registerApp: (NSString *appid)

It should be called whenever WeChat enables the third-party app. The app will appear in Available Apps in WeChat.

Params:
appid WeChat Developer ID
Returns:
Yes (success) or No (failure)

(BOOL) registerApp:withDescription

A member function of WXApi, used for the application registration of third parties in WeChat client program.

BOOL WXApi::registerApp:withDescription: (NSString *appid,[withDescription] NSString *appdesc)

Needs to be called when a third-party application starts each time. It will show in the list of available applications on WeChat after the first call.

Params:
appid WeChat developer ID
appdesc Additional application description, no longer than 1024 bytes
Returns:
Return ‘YES’ if success, otherwise return ‘NO’.

(BOOL) handleOpenURL:delegate

Process the data transferred while WeChat enable the app through URL.

BOOL WXApi::handleOpenURL:delegate: (NSURL *url,[delegate] id< WXApiDelegate > delegate)

Call in application:openURL:sourceApplication:annotation: or application:handleOpenURL

Params:
url URL used to enable the app
delegate Object of WXApiDelegate. It's used to receive messages that trigger WeChat
Returns:
Yes (success) or No (failure)

(BOOL) isWXAppInstalled

Check whether the user has installed WeChat.

BOOL WXApi::isWXAppInstalled ()

Returns:

Yes (WeChat installed) or No (WeChat not installed)

(BOOL) isWXAppSupportApi

Check whether the current WeChat version supports OpenApi.

BOOL WXApi::isWXAppSupportApi ()

Returns:

Yes (support) or No (do not support)

(NSString *) getApiVersion

Get the current SDK version.

NSString * WXApi::getApiVersion ()

Returns:

the current SDK version

(NSString *) getWXAppInstallUrl

Get installation URL of WeChat in iTunes.

NSString * WXApi::getWXAppInstallUrl ()

Returns:

strings about installation URL of WeChat

(BOOL) openWXApp

Open WeChat.

BOOL WXApi::openWXApp ()

Returns:

Yes (success) or No (failure)

(BOOL) sendReq

Send a request to WeChat and wait for onResp returned from WeChat.

BOOL WXApi::sendReq: (BaseReq *req)

The third-party app calls this function, switches to WeChat interface and waits for onResp returned from WeChat. WeChat must calls onResp after the asynchronous processing. Possible requests include SendMessageToWXReq, etc.

Params:
req Specific request. It should be auto-released after calling the function.
Returns:
Yes (success) or No (failure)

(BOOL) sendResp

Send the response of onReq request from WeChat and go to WeChat interface.

BOOL WXApi::sendResp: (BaseResp *resp)

When this function is called, WeChat interface is open. The third-party app receives onResp request from WeChat, processes this request asynchronously and calls this function. Possible requests include GetMessageFromWXResp, ShowMessageFromWXResp, etc.

Params:
resp Specific response. It should be auto-released after calling the function.
Returns:
Yes (success) or No (failure)

WXAppExtendObject

public

App extend object included in multi-media messages.

Import WXApiObject.h; WXAppExtendObject

The third-party app sends a multi-media message that includes WXAppExtendObject to WeChat. WeChat calls this app to process the multi-media contents.

property
(NSString *) url
NSString* WXAppExtendObject::url

If the third-party app does not exist, WeChat will open the download URL of the app.

(NSString *) extInfo
NSString* WXAppExtendObject::extInfo

Custom data of the third-party app. WeChat will return it to the app for processing.

(NSData *) fileData
NSData* WXAppExtendObject::fileData

App file data. When this data is sent to WeChat contacts, the contact needs to click to download. WeChat then returns it to the app for processing.

function
(WXAppExtendObject *) object

Return a WXAppExtendObject object.

WXAppExtendObject * WXAppExtendObject::object ()

WXEmoticonObject

public

Emoticon object included in multi-media messages transferred between WeChat and the third-party app.

Import WXApiObject.h; WXEmoticonObject

property
(NSData *) emoticonData
NSData* WXEmoticonObject::emoticonData

The content of emoticon

function
(WXEmoticonObject *) object

Return a WXEmoticonObject object.

WXEmoticonObject * WXEmoticonObject::object ()

WXFileObject

public

todo

Import WXApiObject.h; WXFileObject

property
(NSString *) fileExtension
NSString* WXFileObject::fileExtension

File Extensions

(NSData *) fileData
NSData* WXFileObject::fileData

File content

function
(WXFileObject *) object

Returns a WXFileObject object.

WXFileObject * WXFileObject::object ()

WXImageObject

public

Image object included in multi-media messages.

Import WXApiObject.h; WXImageObject

The image object included in the message transferred between WeChat and the third-party app

property
(NSData *) imageData
NSData* WXImageObject::imageData

Actual contents of the image

(NSString *) imageUrl
NSString* WXImageObject::imageUrl

Image URL

function
(WXImageObject *) object

Return a WXImageObject object.

WXImageObject * WXImageObject::object ()

WXMediaMessage

public

Import WXApiObject.h; WXMediaMessage

Multi-media contents in the message sent

property
(NSString *) title
NSString* WXMediaMessage::title

Title

(NSString *) description
NSString* WXMediaMessage::description

Description

(NSData *) thumbData
NSData* WXMediaMessage::thumbData

Data of the thumb

(NSString *) mediaTagName
NSString* WXMediaMessage::mediaTagName

todo

(id) mediaObject
id WXMediaMessage::mediaObject

Multi-media data object, including WXWebpageObject, WXImageObject, WXMusicObject, etc.

function
(WXMediaMessage *) message
WXMediaMessage * WXMediaMessage::message ()
(void) setThumbImage

Method used to set the thumb of image message.

void WXMediaMessage::setThumbImage: (UIImage *image)

Params:
image Thumb

WXMusicObject

public

Music object included in multi-media messages.

Import WXApiObject.h; WXMusicObject

Music object included in the message transferred between WeChat and the third-party app

property
(NSString *) musicUrl
NSString* WXMusicObject::musicUrl

URL of music webpage

(NSString *) musicLowBandUrl
NSString* WXMusicObject::musicLowBandUrl

URL of music lowband webpage

(NSString *) musicDataUrl
NSString* WXMusicObject::musicDataUrl

URL of music data

(NSString *) musicLowBandDataUrl
NSString* WXMusicObject::musicLowBandDataUrl

URL of lowband data of the music

function
(WXMusicObject *) object

Return a WXMusicObject object.

WXMusicObject * WXMusicObject::object ()

WXVideoObject

public

Video object included in multi-media messages.

Import WXApiObject.h; WXVideoObject

Video object included in the message transferred between WeChat and the third-party app

property
(NSString *) videoUrl
NSString* WXVideoObject::videoUrl

URL of video data

(NSString *) videoLowBandUrl
NSString* WXVideoObject::videoLowBandUrl

URL of video lowband data

function
(WXVideoObject *) object

Returns a WXVideoObject object.

WXVideoObject * WXVideoObject::object ()

WXWebpageObject

public

Webpage object included in multi-media messages.

Import WXApiObject.h; WXWebpageObject

Webpage object included in the multi-media message transferred between WeChat and the third-party app

property
(NSString *) webpageUrl
NSString* WXWebpageObject::webpageUrl

URL of the webpage

function
(WXWebpageObject *) object

Return a WXWebpageObject object.

WXWebpageObject * WXWebpageObject::object ()

WXApiDelegate-p

public

Receive and process event messages from WeChat.

Import WXApi.h; WXApiDelegate-p

Receive and process event messages from WeChat. Meanwhile WeChat will switch to the third-party app. WXApiDelegate is used and triggered in handleOpenURL.

function
(void) onReq

Receive and process request from WeChat and call sendResp.

void WXApiDelegate-p::onReq: (BaseReq *req)

The third-party app receives a request from WeChat. After asynchronous processing of the request. sendResp should be called to send the result to WeChat. Possible requests include GetMessageFromWXReq, ShowMessageFromWXReq, etc.

Params:
req Specific request contents (auto-released)

(void) onResp

Response of sendReq from WeChat.

void WXApiDelegate-p::onResp: (BaseResp *resp)

The third-party app receives the result from WeChat. If sendReq is called, onResp will be received. Possible results include SendMessageToWXResp, etc.

Params:
Specific response contents (auto-released)

BaseReq

public

Base class of OpenAPI requests

variable
(String) transaction
String transaction

Transaction ID corresponding to this request. It is usually started by Req. Corresponding transaction ID should be populated in Resp.

function
(abstract int) getType
abstract int getType ()

Return type ID of the current request. See ConstantsAPI

Returns:

type of current request instance

(void) toBundle
void toBundle (Bundle data)

Serialize requests into Bundle

Params:
data Bundle that used to carry request data

(void) fromBundle
void fromBundle (Bundle data)

Deserialize request data in Bundle

Params:
data Bundle that used to carry request data

(abstract boolean) checkArgs
abstract boolean checkArgs ()

Check parameters of this request

Returns:

Returns True if all parameters are valid.

BaseResp

public

Base class of OpenAPI responses

variable
(int) errCode
int errCode

Error code. See ErrCode

(String) errStr
String errStr

Invalid texts

(String) transaction
String transaction

Transaction ID corresponding to this request. It is usually created by Req. Corresponding transaction ID should be populated in Resp.

function
(abstract int) getType
abstract int getType ()

Return type ID of the current response. See ConstantsAPI

Returns:

type of current request instance

(void) toBundle
void toBundle (Bundle data)

Serialize responses in Bundle

Params:
data Bundle that used to carry response data

(void) fromBundle
void fromBundle (Bundle data)

Deserialize response data in Bundle

Params:
data Bundle that used to carry response data

(abstract boolean) checkArgs
abstract boolean checkArgs ()

Check parameters of this response

Returns:

Returns True if all parameters are valid.

GetMessageFromWX

public

WeChat sends requests to applications. The application receives the request and call IWXAPI::sendResp() to return the result.

function
GetMessageFromWX
GetMessageFromWX ()

GetMessageFromWX::Req

public

Request class of GetMessageFromWX, extend from BaseReq

variable
(String) username
String username

WeChat name of the user in current conversation

function
Req
Req ()

Build an empty request

Req
Req (Bundle data)

Generate request object from Bundle data

Params:
data Source Bundle that contains request data

(int) getType
int getType ()
(void) toBundle
void toBundle (Bundle data)
(void) fromBundle
void fromBundle (Bundle data)
(boolean) checkArgs
boolean checkArgs ()

GetMessageFromWX::Resp

public

Response class of GetMessageFromWX, extend from BaseResp

variable
(final String) TAG
final String TAG
(WXMediaMessage) message
WXMediaMessage message

WXMediaMessage object returned

function
Resp
Resp ()

Build an empty response

Resp
Resp (Bundle data)

Generate response object from Bundle data

Params:
data Source Bundle that contains response data

(int) getType
int getType ()
(void) fromBundle
void fromBundle (Bundle data)
(void) toBundle
void toBundle (Bundle data)
(boolean) checkArgs
boolean checkArgs ()

SendAuth

public

WeChat OAuth authentication; authorizes applications via WeChat client

function
SendAuth
SendAuth ()

SendAuth::Req

public

Request class of SendAuth, extend from BaseReq

variable
(final String) TAG
final String TAG
(final int) LENGTH_LIMIT
final int LENGTH_LIMIT
(String) scope
String scope

Authorization scope requested by applications

NOTE: 1KB at most

(String) state
String state

used to identify applications; returned by WeChat after authentication. See SendAuth.Resp

NOTE: 1KB at most

function
Req
Req ()

Build an empty request

Req
Req (Bundle data)

Generate request object from Bundle data

Params:
data Source Bundle that contains request data

(int) getType
int getType ()
(void) fromBundle
void fromBundle (Bundle data)
(void) toBundle
void toBundle (Bundle data)
(boolean) checkArgs
boolean checkArgs ()

SendAuth::Resp

public

Response class of SendAuth, extend from BaseResp

variable
(final String) TAG
final String TAG
(final int) LENGTH_LIMIT
final int LENGTH_LIMIT
(String) userName
String userName

User who approves the authorization

(String) token
String token

token for authorization. Null if authorization failed.

(int) expireDate
int expireDate

Expiration time of current authorization (Unix time)

(String) state
String state

used to identify applications; returned by WeChat after authentication. See SendAuth.Req

NOTE: 1KB at most

(String) resultUrl
String resultUrl

Result of auth redirection

function
Resp
Resp ()

Build an empty response

Resp
Resp (Bundle data)

Generate response object from Bundle data

Params:
data Source Bundle that contains response data

(int) getType
int getType ()
(void) fromBundle
void fromBundle (Bundle data)
(void) toBundle
void toBundle (Bundle data)
(boolean) checkArgs
boolean checkArgs ()

SendMessageToWX

public

Message sharing request started by applications

function
SendMessageToWX
SendMessageToWX ()

SendMessageToWX::Req

public

Request class of SendMessageToWX, extend from BaseReq

variable
(final int) WXSceneSession
final int WXSceneSession

Send to WeChat conversation

(final int) WXSceneTimeline
final int WXSceneTimeline

Send to WeChat Moments

(final String) TAG
final String TAG
(WXMediaMessage) message
WXMediaMessage message

WXMediaMessage data of the sharing request

(int) scene
int scene

Target of sharing. Share to WeChat conversation (WXSceneSession) or WeChat Moments (WXSceneTimeline). Share to WeChat conversation by default.

function
Req
Req ()

Build an empty request

Req
Req (Bundle data)

Generate request object from Bundle data

Params:
data Source Bundle that contains request data

(int) getType
int getType ()
(void) fromBundle
void fromBundle (Bundle data)
(void) toBundle
void toBundle (Bundle data)
(boolean) checkArgs
boolean checkArgs ()

SendMessageToWX::Resp

public

Response class of SendMessageToWX, extend from BaseResp

function
Resp
Resp ()

Build an empty response

Resp
Resp (Bundle data)

Generate response object from Bundle data

Params:
data Source Bundle that contains response data

(int) getType
int getType ()
(void) fromBundle
void fromBundle (Bundle data)
(void) toBundle
void toBundle (Bundle data)
(boolean) checkArgs
boolean checkArgs ()

ShowMessageFromWX

public

Message displaying request that WeChat sends to applications

function
ShowMessageFromWX
ShowMessageFromWX ()

ShowMessageFromWX::Req

public

Request class of ShowMessageFromWX, inherited from BaseReq

variable
(WXMediaMessage) message
WXMediaMessage message

WXMediaMessage data that WeChat requests application to display

function
Req
Req ()

Build an empty request

Req
Req (Bundle data)

Generate request object from Bundle data

Params:
data Source Bundle that contains request data

(int) getType
int getType ()
(void) toBundle
void toBundle (Bundle data)
(void) fromBundle
void fromBundle (Bundle data)
(boolean) checkArgs
boolean checkArgs ()

ShowMessageFromWX::Resp

public

Response class of ShowMessageFromWX, inherited from BaseResp

function
Resp
Resp ()

Build an empty response

Resp
Resp (Bundle data)

Generate response object from Bundle data

Params:
data Source Bundle that contains response data

(int) getType
int getType ()
(boolean) checkArgs
boolean checkArgs ()

WXAPIFactory

public

Factory class of IWXAPI interface, which will be used by the application as entry of openapi

variable
(WXAPIFactory) instance
WXAPIFactory instance
function
WXAPIFactory
WXAPIFactory ()
(IWXAPI) createWXAPI
static IWXAPI createWXAPI (final Context context, String appId)

Create WXAPI access interface

Params:
context Create Context object of WXAPI
appId Create appId of WXAPI interface.
Returns:
IWXAPI object

(IWXAPI) createWXAPI
static IWXAPI createWXAPI (final Context context, String appId, boolean checkSignature)

Create WXAPI access interface

Params:
context Create Context object of WXAPI
appId Create appId of WXAPI interface.
checkSignature Check whether the WeChat client uses official signature
Returns:
IWXAPI object

WXApiImplV10

package

implement class for IWXAPI version 1.0

variable
(final String) TAG
final String TAG
(final String) WXAPP_PACKAGE_NAME
final String WXAPP_PACKAGE_NAME
(final String) WX_APP_SIGNATURE
final String WX_APP_SIGNATURE
(Context) context
Context context
(String) appId
String appId
(boolean) checkSignature
boolean checkSignature
function
WXApiImplV10
WXApiImplV10 (final Context context, final String appId)
WXApiImplV10
WXApiImplV10 (final Context context, final String appId, final boolean checkSignature)
(boolean) registerApp
boolean registerApp (final String appId)
(void) unregisterApp
void unregisterApp ()
(boolean) handleIntent
boolean handleIntent (Intent data, IWXAPIEventHandler handler)
(boolean) isWXAppInstalled
boolean isWXAppInstalled ()
(boolean) isWXAppSupportAPI
boolean isWXAppSupportAPI ()
(int) getWXAppSupportAPI
int getWXAppSupportAPI ()
(boolean) openWXApp
boolean openWXApp ()
(boolean) openWXApp
boolean openWXApp (String userName)
(boolean) sendReq
boolean sendReq (BaseReq req)
(boolean) sendResp
boolean sendResp (BaseResp resp)
(boolean) isIntentFromWx
boolean isIntentFromWx (Intent intent)
(boolean) validateAppSignatureForPackage
boolean validateAppSignatureForPackage (String packageName)

from facebook sdk

Params:
context
packageName
Returns:

(boolean) validateAppSignature
boolean validateAppSignature (Signature[] signatures)
(byte[]) genCheckSum
byte [] genCheckSum (final String content, final int sdkVersion, final String packageName)
(boolean) checkSumConsistent
boolean checkSumConsistent (final byte[] src, final byte[] gen)

WXAppExtendObject

public

WXAppExtendObject

Derived class of WXMediaMessage.IMediaObject; used to describe a application object.

Used as the unique identifier of applications; returned by WeChat after authentication. See SendAuth.Req NOTE: extInfo, filePath and fileData can not be null at that same time.

filePath and fileData are not used at the same time.

variable
(final String) TAG
final String TAG
(final int) EXTINFO_LENGTH_LIMIT
final int EXTINFO_LENGTH_LIMIT
(final int) PATH_LENGTH_LIMIT
final int PATH_LENGTH_LIMIT
(final int) CONTENT_LENGTH_LIMIT
final int CONTENT_LENGTH_LIMIT
(String) extInfo
String extInfo

Extend text data for applications

NOTE: 2KB at most.

(String) filePath
String filePath

Local directory of the file provided for applications

NOTE: The length should be within 10KB and content size within 10MB.

(byte[]) fileData
byte [] fileData

File binary data for applications

NOTE: Content size should be within 10MB

function
WXAppExtendObject
WXAppExtendObject ()
WXAppExtendObject
WXAppExtendObject (String extInfo, byte[] fileData)

Constructor

Params:
extInfo Extend text data provided for applications
fileData File binary data provided for applications

WXAppExtendObject
WXAppExtendObject (String extInfo, String filePath)

Constructor

Params:
extInfo Extend text data provided for applications
filePath File directory provided for applications

(void) serialize
void serialize (Bundle data)

Serialize member variables to bundle object

Params:
data Target bundle object

(void) unserialize
void unserialize (Bundle data)

Deserialize bundle object to initialize member variables

Params:
data Data source bundle object

(int) type
int type ()

Load type of the current media object

Returns:

type Type of the current media object

(boolean) checkArgs
boolean checkArgs ()

Check validity of parameters of MediaObject

Returns:

True if all parameters are valid.

(int) getFileSize
int getFileSize (String filePath)

WXAppLaunchData

public

variable
(final String) ACTION_HANDLE_WXAPPLAUNCH
final String ACTION_HANDLE_WXAPPLAUNCH
(final String) ACTION_HANDLE_WXAPP_RESULT
final String ACTION_HANDLE_WXAPP_RESULT
(final String) ACTION_HANDLE_WXAPP_SHOW
final String ACTION_HANDLE_WXAPP_SHOW
(int) launchType
int launchType
(String) message
String message

WXAppLaunchData::Builder

public

function
(WXAppLaunchData) fromBundle
static WXAppLaunchData fromBundle (Bundle data)
(Bundle) toBundle
static Bundle toBundle (WXAppLaunchData obj)

WXEmojiObject

public

WXEmojiObject

Derived class of WXMediaMessage.IMediaObject. Used to describe an emoji object

NOTE: emojiData and emojiPath can not be null at the same time.

variable
(final String) TAG
final String TAG
(final int) CONTENT_LENGTH_LIMIT
final int CONTENT_LENGTH_LIMIT
(byte[]) emojiData
byte [] emojiData

Binary data of the emoji

(String) emojiPath
String emojiPath

Local directory of the emoji

function
WXEmojiObject
WXEmojiObject ()
WXEmojiObject
WXEmojiObject (final byte[] emojiData)

Constructor

Params:
emojiData Binary data of the emoji. Used to create a new object.

WXEmojiObject
WXEmojiObject (final String emojiPath)

Constructor

Params:
emojiPath Local directory of the emoji. Used to create a new object.

(void) setEmojiData
void setEmojiData (final byte[] emojiData)
(void) setEmojiPath
void setEmojiPath (final String emojiPath)
(void) serialize
void serialize (Bundle data)

Serialize member variables to bundle object

Params:
data Target bundle object

(void) unserialize
void unserialize (Bundle data)

Deserialize bundle object to initialize member variables

Params:
data Data source bundle object

(int) type
int type ()

Load type of the current media object

Returns:

type Type of the current media object

(boolean) checkArgs
boolean checkArgs ()

Check validity of parameters of MediaObject

Returns:

True if all parameters are valid.

(int) getFileSize
int getFileSize (String filePath)

WXFileObject

public

WXFileObject

Derived class of WXMediaMessage.IMediaObject. Used to describe a file object

NOTE: fileData and filePath can not be null at the same time.

variable
(final String) TAG
final String TAG
(final int) CONTENT_LENGTH_LIMIT
final int CONTENT_LENGTH_LIMIT
(byte[]) fileData
byte [] fileData

Binary data of the file

(String) filePath
String filePath

Local directory of the file

function
WXFileObject
WXFileObject ()
WXFileObject
WXFileObject (final byte[] fileData)

Constructor

Params:
fileData Binary data of the file. Used to create a new object.

WXFileObject
WXFileObject (final String filePath)

Constructor

Params:
filePath Local directory of the file. Used to create a new object.

(void) setFileData
void setFileData (final byte[] fileData)
(void) setFilePath
void setFilePath (final String filePath)
(void) serialize
void serialize (Bundle data)

Serialize member variables to bundle object

Params:
data Target bundle object

(void) unserialize
void unserialize (Bundle data)

Deserialize bundle object to initialize member variables

Params:
data Data source bundle object

(int) type
int type ()

Load type of the current media object

Returns:

type Type of the current media object

(boolean) checkArgs
boolean checkArgs ()

Check validity of parameters of MediaObject

Returns:

True if all parameters are valid.

(int) getFileSize
int getFileSize (String filePath)

WXImageObject

public

WXImageObject

Derived class of WXMediaMessage.IMediaObject. Used to describe an image object

NOTE: imageData, imagePath and imageUrl can not be null at the same time.

imageData, imagePath and imageUrl will not be used at the same time.

variable
(final String) TAG
final String TAG
(final int) CONTENT_LENGTH_LIMIT
final int CONTENT_LENGTH_LIMIT
(final int) PATH_LENGTH_LIMIT
final int PATH_LENGTH_LIMIT
(final int) URL_LENGTH_LIMIT
final int URL_LENGTH_LIMIT
(byte[]) imageData
byte [] imageData

Binary data of an image

NOTE: Content size should be within 10MB

(String) imagePath
String imagePath

Local directory of an image

NOTE: The length should be within 10KB and content size within 10MB.

(String) imageUrl
String imageUrl

URL of an image

NOTE: The length should be within 10KB.

function
WXImageObject
WXImageObject ()
WXImageObject
WXImageObject (final byte[] bitmap)

Constructor

Params:
bitmap Binary data of a bitmap. Used to create a new object.

WXImageObject
WXImageObject (final Bitmap bm)

Create an object via bitmap

(void) setImagePath
void setImagePath (final String imagePath)
(void) serialize
void serialize (Bundle data)

Serialize member variables to bundle object

Params:
data Target bundle object

(void) unserialize
void unserialize (Bundle data)

Deserialize bundle object to initialize member variables

Params:
data Data source bundle object

(int) type
int type ()

Load type of the current media object

Returns:

type Type of the current media object

(boolean) checkArgs
boolean checkArgs ()

Check validity of parameters of MediaObject

Returns:

True if all parameters are valid.

(int) getFileSize
int getFileSize (String filePath)

WXMediaMessage

public

Contents of WeChat media message

variable
(final String) TAG
final String TAG
(final int) THUMB_LENGTH_LIMIT
final int THUMB_LENGTH_LIMIT
(final int) TITLE_LENGTH_LIMIT
final int TITLE_LENGTH_LIMIT
(final int) DESCRIPTION_LENGTH_LIMIT
final int DESCRIPTION_LENGTH_LIMIT
(final String) ACTION_WXAPPMESSAGE
final String ACTION_WXAPPMESSAGE

Default ACTION of WeChat media message

(int) sdkVer
int sdkVer

SDK version number

(String) title
String title

Message title

NOTE: The length should be within 512Bytes

(String) description
String description

Message description

NOTE: The length should be within 1KB.

(byte[]) thumbData
byte [] thumbData

Binary data of a thumbnail image

NOTE: The file size should be within 32KB.

(IMediaObject) mediaObject
IMediaObject mediaObject
(byte[]) headImgData
byte [] headImgData
function
WXMediaMessage
WXMediaMessage ()
WXMediaMessage
WXMediaMessage (IMediaObject object)

Constructor

Params:
object Media object. Used to build a new object.

(int) getType
int getType ()

Load type of the media object

Returns:

Type of the media object

(void) setThumbImage
void setThumbImage (Bitmap bm)

Set the thumbnail via bitmap object

Params:
bm Bitmap object that used to set thumbnail

(void) setHeadImg
void setHeadImg (Bitmap bm)
(boolean) checkArgs
boolean checkArgs ()

WXMediaMessage::Builder

public

Builder for WXMediaMessage

variable
(final String) KEY_IDENTIFIER
final String KEY_IDENTIFIER

Key value of bundle. Used as the unique identifier of a media type

function
(Bundle) toBundle
static Bundle toBundle (final WXMediaMessage obj)

Serialize a WXMediaMessage object to bundle

Params:
obj WXMediaMessage object that to be serialized
Returns:
Target bundle object of serialization

(WXMediaMessage) fromBundle
static WXMediaMessage fromBundle (final Bundle data)

Deserialize bundle to build a WXMediaMessage object

Params:
data bundle object that used for deserialization
Returns:
WXMediaMessage object that built via deserialization

WXMusicObject

public

WXMusicObject

Derived class of WXMediaMessage.IMediaObject. Used to describe an audio object

NOTE: musicUrl and musicLowBandUrl can not be null at the same time.

variable
(final String) TAG
final String TAG
(final int) LENGTH_LIMIT
final int LENGTH_LIMIT
(String) musicUrl
String musicUrl

Audio Webpage URL

NOTE: The length should be within 10KB.

(String) musicLowBandUrl
String musicLowBandUrl

Audio Webpage URL for low bandwidth

NOTE: The length should be within 10KB.

(String) musicDataUrl
String musicDataUrl

Audio File URL

NOTE: The length should be within 10KB.

(String) musicLowBandDataUrl
String musicLowBandDataUrl

Audio File URL for low bandwidth

NOTE: The length should be within 10KB.

function
(void) serialize
void serialize (Bundle data)

Serialize member variables to bundle object

Params:
data Target bundle object

(void) unserialize
void unserialize (Bundle data)

Deserialize bundle object to initialize member variables

Params:
data Data source bundle object

(int) type
int type ()

Load type of the current media object

Returns:

type Type of the current media object

(boolean) checkArgs
boolean checkArgs ()

Check validity of parameters of MediaObject

Returns:

True if all parameters are valid.

WXTextObject

public

WXTextObject

Derived class of WXMediaMessage.IMediaObject. Used to describe a text object.

variable
(final String) TAG
final String TAG
(final int) LENGTH_LIMIT
final int LENGTH_LIMIT
(String) text
String text

Text data

NOTE: The length should be within 10KB.

function
WXTextObject
WXTextObject ()
WXTextObject
WXTextObject (final String text)

Constructor

Params:
text Text data

(void) serialize
void serialize (Bundle data)

Serialize member variables to bundle object

Params:
data Target bundle object

(void) unserialize
void unserialize (Bundle data)

Deserialize bundle object to initialize member variables

Params:
data Data source bundle object

(int) type
int type ()

Load type of the current media object

Returns:

type Type of the current media object

(boolean) checkArgs
boolean checkArgs ()

Check validity of parameters of MediaObject

Returns:

True if all parameters are valid.

WXVideoObject

public

WXVideoObject

Derived class of WXMediaMessage.IMediaObject. Used to describe a video object

NOTE: videoUrl and videoLowBandUrl can not be null at the same time.

variable
(final String) TAG
final String TAG
(final int) LENGTH_LIMIT
final int LENGTH_LIMIT
(String) videoUrl
String videoUrl

Video URL

NOTE: The length should be within 10KB.

(String) videoLowBandUrl
String videoLowBandUrl

Video URL for low bandwidth

NOTE: The length should be within 10KB.

function
(void) serialize
void serialize (Bundle data)

Serialize member variables to bundle object

Params:
data Target bundle object

(void) unserialize
void unserialize (Bundle data)

Deserialize bundle object to initialize member variables

Params:
data Data source bundle object

(int) type
int type ()

Load type of the current media object

Returns:

type Type of the current media object

(boolean) checkArgs
boolean checkArgs ()

Check validity of parameters of MediaObject

Returns:

True if all parameters are valid.

WXWebpageObject

public

WXWebpageObject

Derived class of WXMediaMessage.IMediaObject. Used to describe a webpage object.

variable
(final String) TAG
final String TAG
(final int) LENGTH_LIMIT
final int LENGTH_LIMIT
(String) webpageUrl
String webpageUrl

html URL

NOTE:The length should be within 10KB.

function
WXWebpageObject
WXWebpageObject ()
WXWebpageObject
WXWebpageObject (final String url)

Constructor

Params:
url html URL

(void) serialize
void serialize (Bundle data)

Serialize member variables to bundle object

Params:
data Target bundle object

(void) unserialize
void unserialize (Bundle data)

Deserialize bundle object to initialize member variables

Params:
data Data source bundle object

(int) type
int type ()

Load type of the current media object

Returns:

type Type of the current media object

(boolean) checkArgs
boolean checkArgs ()

Check validity of parameters of MediaObject

Returns:

True if all parameters are valid.

BaseResp::ErrCode

public

Error code for OpenAPI responses

variable
(final int) ERR_OK
final int ERR_OK

Returned normally

(final int) ERR_COMM
final int ERR_COMM

General errors

(final int) ERR_USER_CANCEL
final int ERR_USER_CANCEL

User canceled

(final int) ERR_SENT_FAILED
final int ERR_SENT_FAILED

Unable to send

(final int) ERR_AUTH_DENIED
final int ERR_AUTH_DENIED

Authentication failed

(final int) ERR_UNSUPPORT
final int ERR_UNSUPPORT

Unsupport error

ConstantsAPI

public

WeChatOpenAPI Constants

variable
(final String) ACTION_HANDLE_APP_REGISTER
final String ACTION_HANDLE_APP_REGISTER

Register the third-party app to WeChat. The registered app will be shown in the plus (+) section of WeChat.

(final String) ACTION_HANDLE_APP_UNREGISTER
final String ACTION_HANDLE_APP_UNREGISTER

Un-register the app to WeChat. The un-registered app will not be shown in the plus (+) section of Wechat.

(final String) ACTION_REFRESH_WXAPP
final String ACTION_REFRESH_WXAPP

Broadcast event Action sent by WeChat. It's used to notify Apps for registration.

(final int) COMMAND_UNKNOWN
final int COMMAND_UNKNOWN

unknown command

(final int) COMMAND_SENDAUTH
final int COMMAND_SENDAUTH

Send OpenAPI Auth

(final int) COMMAND_SENDMESSAGE_TO_WX
final int COMMAND_SENDMESSAGE_TO_WX

Share information to WeChat

(final int) COMMAND_GETMESSAGE_FROM_WX
final int COMMAND_GETMESSAGE_FROM_WX

WeChat requests the third-party app for message data.

(final int) COMMAND_SHOWMESSAGE_FROM_WX
final int COMMAND_SHOWMESSAGE_FROM_WX

WeChat requests the third-party app to display message data.

(final String) WX_TOKEN_KEY
final String WX_TOKEN_KEY
(final String) WX_TOKEN_VALUE
final String WX_TOKEN_VALUE

IWXAPI

public

WeChat OpenAPI access interface

Entry of OpenAPI functions; creates instances via WXAPIFactory

function
(boolean) registerApp
boolean registerApp (String appId)

Register WeChat app. Registered apps will be shown in the app list of WeChat.

Params:
appId App ID of the third-party app
Returns:
True if operation succeeded; and the app will be shown in WeChat. Otherwise not.

(void) unregisterApp
void unregisterApp ()

Un-register WeChat app. The app will not be shown in WeChat app list if operation succeeded.

(boolean) handleIntent
boolean handleIntent (Intent data, IWXAPIEventHandler handler)

Call IWXAPI#handleIntent(Intent, IWXAPIEventHandler) in BroadcastReceiver. For example

class SampleEventProcessor extends BroadcastReceiver implements IWXAPIEventHandler {
// override broadcast receiver
public void onReceive(Context context, Intent data) {
final IWXAPI api = WXAPIFactory.createWXAPI(context, null);
if (api.handleIntent(data, this)) {
// intent handled as wechat request/response
return;
}
// process other intent as you like
}
// process request
public void onReq(BaseReq req) {
switch (req.getType()) {
case ConstantsAPI.COMMAND_GETMESSAGE_FROM_WX:
Toast.makeText(context, "get message from wx, processed here", Toast.LENGTH_LONG).show();
break;
case ConstantsAPI.COMMAND_SHOWMESSAGE_FROM_WX:
Toast.makeText(context, "show message from wx, processed here", Toast.LENGTH_LONG).show();
break;
default:
break;
}
}
// process response
public void onResp(BaseResp resp) {
switch (resp.getType()) {
case ConstantsAPI.COMMAND_SENDAUTH:
Toast.makeText(context, "get auth resp, processed here", Toast.LENGTH_LONG).show();
break;
case ConstantsAPI.COMMAND_SENDMESSAGE_TO_WX:
// Process SendMessageToWX.Resp returned by WeChat
Toast.makeText(context, "send messsage to wx resp, processed here", Toast.LENGTH_LONG).show();
break;
default:
break;
}
}
}

and DON'T FORGET to add SampleEventProcessor BroadcastReceiver in AndroidManifest.xml

Params:
data
handler
Returns:
true if handled

(boolean) isWXAppInstalled
boolean isWXAppInstalled ()

check wechat app installation status

Returns:

true if installed

(boolean) isWXAppSupportAPI
boolean isWXAppSupportAPI ()

check api level that supported by wechat app which has been installed

Returns:

true if support

(int) getWXAppSupportAPI
int getWXAppSupportAPI ()

get api level from installed wechat app

Returns:

api level

(boolean) openWXApp
boolean openWXApp ()

get supported api level from installed wechat app

Returns:

an array of two integers in which to hold the min and max sdk version supported by wechat app. the array is like [min_sdk_version, max_sdk_version] launch wechat apptrue if launched

(boolean) openWXApp
boolean openWXApp (String userName)

launch wechat app

Returns:

true if launched

(boolean) sendReq
boolean sendReq (BaseReq req)

send request to wechat app

Params:
req
Returns:
true if sent

(boolean) sendResp
boolean sendResp (BaseResp resp)

send response to wechat app, make sure that the response have same transaction with request

Params:
resp
Returns:
true if sent

IWXAPIEventHandler

public

Interface used to receive requests and responses

function
(void) onReq
void onReq (BaseReq req)

This method is called when a request is built from bundle.

Params:
req Request object that newly built

(void) onResp
void onResp (BaseResp resp)

This method is called when a response is built from bundle.

Params:
resp Response object that newly built

WXMediaMessage::IMediaObject

public

WXMediaMessage::IMediaObject

Interface of media message

variable
(final int) TYPE_UNKNOWN
final int TYPE_UNKNOWN

Unknown message type; should be ignored

(final int) TYPE_TEXT
final int TYPE_TEXT

Text message. It refers to plain text message (see WXImageObject) but not WeChat texts

(final int) TYPE_IMAGE
final int TYPE_IMAGE

Image message (see also WXImageObject)

(final int) TYPE_MUSIC
final int TYPE_MUSIC

Music message (see also WXMusicObject)

(final int) TYPE_VIDEO
final int TYPE_VIDEO

Video message (see also WXVideoObject)

(final int) TYPE_URL
final int TYPE_URL

Webpage message (see also WXWebpageObject)

(final int) TYPE_FILE
final int TYPE_FILE

File sharing message (see also WXFileObject)

(final int) TYPE_APPDATA
final int TYPE_APPDATA

Type of application extend message. See also WXAppExtendObject

(final int) TYPE_EMOJI
final int TYPE_EMOJI

Emoji message (see also WXEmojiObject)

function
(void) serialize
void serialize (Bundle data)

Serialize member variables to bundle object

Params:
data Target bundle object

(void) unserialize
void unserialize (Bundle data)

Deserialize bundle object to initialize member variables

Params:
data Data source bundle object

(int) type
int type ()

Load type of the current media object

Returns:

type Type of the current media object

(abstract boolean) checkArgs
abstract boolean checkArgs ()

Check validity of parameters of MediaObject

Returns:

True if all parameters are valid.