Note: This article is WeChat WP8 Tutorial for novice users of terminal development tools, involving only professors SDK The default reader is already familiar with VS2012 Basic use method, and have a certain programming knowledge base.

# 1. Apply for your AppID

Please come. Developer Application Registration Page After registering and selecting the mobile app to set up, you will get AppID, available for immediate development. However, applications need to be submitted for review after the completion of registration, and only approved applications can be officially released.

# 2.WeChat Terminal SDK Development kit

SDK Development package includes 3 Files:

MicroMsg SDK.dll (every third-party application must import this sdk Library for interaction with WeChat

-MicroMsgSDK.XML(API Document, put with MicroMsgSDK.dll The same directory, in the VS Can provide help in, for example, viewing function comments)

-Google.ProtocolBuffersLite.dll(Google of ProtocolBuffer Open source library for serializing data, just by introduction)

Please proceed to[Resource Download Page](/doc/oplatform/Downloads/WP8_Resource. html) SDK package

# 3. Building the development environment

[1] in VS2012 Build your project in.

[2] As shown below, right-click on the project's References, select from the shortcut menu Add References, click the "Browser" on on the open pop-up box, and select WP8 platform SDK Development kit Two of them. dll File.

[3] Introduce SDK of dll After, in References You can see the introduction of dll Coop. (Shown below).

SDK The namespace is MicroMsg.sdk, import this namespace before using it.

using MicroMsg.sdk

# 4. using the SDK Development kit

[1] Send request or response to WeChat

Now, your application will send a request or response to WeChat by IWXAPI of sendReq and sendResp Two functions to implement.

boolean sendReq(BaseReq req)

sendReq It's a third party. app Actively send a request to WeChat, send the request will pull up the WeChat application, WeChat after processing the request, will send a response back App。

boolean sendResp(BaseResp (resp)

sendResp Scenario: WeChat first to the third party app Send the request, pull up the third party App Interface, when the user operation is completed, a third party app adopt sendResp Send response data to WeChat, pull up the WeChat interface.

sendReq Example:

try

{

int scene = SendMessageToWX.Req.WXSceneSession //Send to WeChat friends`

WXTextMessage message = new WXTextMessage()

message.Title = "Text."

message.Text = "This is a piece of text."

SendMessageToWX.Req req = new SendMessageToWX.Req(message, scene)

IWXAPI api = WXAPIFactory.CreateWXAPI(AppID)

api. SendReq(req)

}

catch (WXException (ex)

{

MessageBox.Show(ex. Message)

}

AppID For you to register the application on WeChat open platform website AppID To.

Note that SendMessageToWX. Req of scene Parameter, if scene fill WX Scene Session, then the message will be sent to WeChat friends. if scene fill WX Scene Timeline, then the message will be sent to the circle of friends. if scene fill WXSceneChooseByUser, then it's up to the user to choose whether to send it to friends or to Moments. scene Default value is WXSceneChooseByUser。

sendResp Example:

try
{
WXTextMessage message = new WXTextMessage()
message.Title = "Text."
message.Text = "This is a piece of text."
GetMessageFromWX.Or or = new GetMessageFromWX.Or(req.Transaction, req.Username, message)
IWXAPI api = WXAPIFactory.CreateWXAPI(AppID)
api. SendResp((resp)
}
catch (WXException (ex)
{
MessageBox.Show(ex. Message)
}

req The data object that comes in when you send a request for WeChat to your app.

Specific content to be sent by a third party app Developer Definition, SDK Support text, pictures, documents, links, expressions, music, video, custom and other messages. Specific reference Demo Source code.

[2] Handle WeChat requests and responses

If your application needs to receive requests and responses sent by WeChat, you need the following 4 Step operation: a. modify WMAppManifest.xml

A. A. A. Modification WMAppManifest.xml

Right-click on the app Properties Down WMAppManifest.xml, select Open With... and then select Xml (Text) Edit Open the file. Before, add the following tag code(If a tag already exists in your file, add it under the existing tag)

Above Xml There are two changes in the clip. One is Name="SDK_DEMO " Change it to any name you like. Two supported. File Type, one is. wechatapp, The other one is... wx3b34a14b66641dfd, Where the "wx3b34a14b66641dfd" changed to "when you register the application on WeChat open platform" AppID, this must be written right, or WeChat can not pull your application.

b. Write WeChat entry Page class

inheritance WXEntryBasePage Class, and overwrite the table function, to handle requests and responses from WeChat, WeChat sent data, has been filled in the parameters, can be directly used. Note: if overridden OnNavigatedTo Function, you need to call Base.OnNavigatedTo ensure that logic in the parent class is executed.

c. Inheritance system UriMapperBase class

The general logic is as follows:

class AssociationUriMapper : UriMapperBase
{
private string tempUri
public override Uri MapUri(Uri uri)
{
tempUri = uri. ToString()
// Open programs by file type
if (tempUri.Contains("/FileTypeAssociation"))
{
// Get fileID (after "fileToken=").
int fileIDIndex = tempUri.IndexOf("fileToken=") + 10
string fileID = tempUri.Substring(fileIDIndex)
// Gets the file name. string incommingFileName = SharedStorageAccessManager.GetSharedFileName(fileID)
// Get File Suffix
int extensionIndex = incommingFileName.LastIndexOf(&#39.&#39) + 1
string incommingFileType = incommingFileName.Substring(extensionIndex).ToLower()
// Jump the addresses of different parameters depending on the file type
switch (incommingFileType)
{
case "wx3b34a14b66641dfd":
return new Uri("/DemoEntryPage.xamlfileToken=" + fileID, UriKind.Relative)
default:
return new Uri("/MainPage.xaml", UriKind.Relative)
}
}
else
{
return uri
}
}
}

case 'wx3b34a14b66641dfd': Make it yours. AppID To.

"/DemoEntryPage.xamlfileToken=" Change the steps b Middle inheritance WXEntryBasePage of Page Path.

d. modify App.xaml.cs file

And then after App.xaml.cs of InitializePhoneApplication(Function, add a line of code:

// Assign the URI-mapper class to the application frame.

RootFrame.UriMapper = new AssociationUriMapper()

Note:

    1. When testing, make sure you install the WP8 WeChat(4.0 (above)
    1. Don't be Demo To form your application, because if other people do what you do, your AppStore On AppID It's the same.

WeChat SDK Sample Demo source code