微信公共平台api测试

微信收费的传闻搞的沸沸扬扬,无非就是利益之争!不过这和我们关系不大。即使收费也是企鹅和无线运营商的事!言归正传,下面说下微信公共平台测试的情况:

1、http://mp.weixin.qq.com/cgi-bin/loginpage?t=wxm2-login&lang=zh_CN 需要到这里注册账号,才能使用。

2、提供的功能目前还比较少(相对其他开发平台的api,比如微博),但是web的console看着还算是比较清爽的。

1

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、接受消息,回复消息我基本都测试了一下,速度还是很快的!

10、想看下效果的,请用微信扫描下,conseb ,回复的都很好看!

(下面使用live write二次修改的)

2013-04-12 145909_副本

11、想目前通过api方式推送的,请看这里 https://github.com/zscorpio/weChat

本文通过live write发布

转载于:https://my.oschina.net/yasenagat/blog/122364

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值