微信收费的传闻搞的沸沸扬扬,无非就是利益之争!不过这和我们关系不大。即使收费也是企鹅和无线运营商的事!言归正传,下面说下微信公共平台测试的情况:
1、http://mp.weixin.qq.com/cgi-bin/loginpage?t=wxm2-login&lang=zh_CN 需要到这里注册账号,才能使用。
2、提供的功能目前还比较少(相对其他开发平台的api,比如微博),但是web的console看着还算是比较清爽的。
3、设置选项卡里面,完善各种信息!
4、码农请直接点到高级功能!
高级功能分为编辑模式和开发模式,明显是开发模式
5、需要认证!
提供一个域名地址,必须是80端口,比如www.abc.com,二级域名也可,不是首页也可以,比如xxoo.abc.com/xxoo.jsp
填写token
6、把微信上面的测试代码copy到你的认证域名指向的页面!(测试的是php的,其他同理)
因为你们都比较懒,直接贴上代码:
<?php
/**
* wechat php test
*///define your token
define("TOKEN", "weixin");
$wechatObj = new wechatCallbackapiTest();
$wechatObj->valid();class wechatCallbackapiTest
{
public function valid()
{
$echoStr = $_GET["echostr"];//valid signature , option
if($this->checkSignature()){
echo $echoStr;
exit;
}
}public function responseMsg()
{
//get post data, May be due to the different environments
$postStr = $GLOBALS["HTTP_RAW_POST_DATA"];//extract post data
if (!empty($postStr)){
$postObj = simplexml_load_string($postStr, 'SimpleXMLElement', LIBXML_NOCDATA);
$fromUsername = $postObj->FromUserName;
$toUsername = $postObj->ToUserName;
$keyword = trim($postObj->Content);
$time = time();
$textTpl = "<xml>
<ToUserName><![CDATA[%s]]></ToUserName>
<FromUserName><![CDATA[%s]]></FromUserName>
<CreateTime>%s</CreateTime>
<MsgType><![CDATA[%s]]></MsgType>
<Content><![CDATA[%s]]></Content>
<FuncFlag>0</FuncFlag>
</xml>";
if(!empty( $keyword ))
{
$msgType = "text";
$contentStr = "Welcome to wechat world!";
$resultStr = sprintf($textTpl, $fromUsername, $toUsername, $time, $msgType, $contentStr);
echo $resultStr;
}else{
echo "Input something...";
}}else {
echo "";
exit;
}
}
private function checkSignature()
{
$signature = $_GET["signature"];
$timestamp = $_GET["timestamp"];
$nonce = $_GET["nonce"];
$token = TOKEN;
$tmpArr = array($token, $timestamp, $nonce);
sort($tmpArr);
$tmpStr = implode( $tmpArr );
$tmpStr = sha1( $tmpStr );
if( $tmpStr == $signature ){
return true;
}else{
return false;
}
}
}?>
7、查看api http://mp.weixin.qq.com/wiki/index.php?title=%E9%A6%96%E9%A1%B5
8、api写的都比较清楚,目前不支持消息的群发!编辑模式是支持的,但是每天只有可怜的一条!貌似是这样的!
9、接受消息,回复消息我基本都测试了一下,速度还是很快的!
(下面使用live write二次修改的)
11、想目前通过api方式推送的,请看这里 https://github.com/zscorpio/weChat
本文通过live write发布