1.在创建应用时选择使用git进行版本控制
2.在本地新建一个项目文件夹,比如我在D盘新建了一个WeChat文件夹
3.在BAE上复制一下自己的git 地址
4.然后cmd打开命令控制行(win+r --> 输入cmd)
5.进入自己本地项目的文件夹
6.进入这个文件夹后 git clone + 复制的git地址
7.接下来就输入自己的BAE的用户名和密码
8.然后你回到本地WeChat文件夹下面多了个文件夹,名字是自己在BAE上那个项目的APPID
9.打开就会发现里面有两个文件
10.这时候新建一个文件api.php,然后把微信公众平台对接的示例代码copy过来
wx_example.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; } } } ?>
默认token时“weixin”
然后保存
11.继续在命令行中,cd +(appid)
git status
命令行会显示一个红色字体 api.php
12.git add api.php 存储到本地(git add. 表所有)
git commit -m '这里可以加注数'
git push同步到云库中
再次输入用户名 密码
13.然后回到BAE你会发现项目那里会有新版本的提示,点击一下右边的快捷发布
14.打开公众平台->开发者中心填写URL和token
15.用这个项目地址+api.php作为URL
一开始不成功,提交几次就好了
当我修改一个文件的时候我想要同步怎么办呢?我是这么解决
1.进入修改文件的目录+git clone +复制的git地址
2.git add index.php(假设我修改的是index.php)
3.git commit -m"I made some changes"
4.git push
5.输入用户名和密码 就会出现
6.回到BAE再次快捷发布
搞定拉!!!
以上纯属小白的操作,不正确步骤请指出(●'◡'●)