来源:自学PHP网 时间:2015-04-14 12:58 作者: 阅读:次
[导读] 最近看到有用sae+微信公众平台控制嵌入式设备的帖子,,额。。。。嫉妒羡慕恨啊。挺羡慕那些搞单片机嵌入式的,额更牛b的估计是那些遥控小强,乌龟,金鱼(春晚,呵呵)自己就码...
|
最近看到有用sae+微信公众平台控制嵌入式设备的帖子,,额。。。。嫉妒羡慕恨啊。
挺羡慕那些搞单片机嵌入式的,额更牛b的估计是那些遥控小强,乌龟,金鱼(春晚,呵呵)
使用方法
2. 在要控制的电脑上下载桌面端 http://files.cnblogs.com/hehe108/Remote.rar
开发环境 php,sae,vs2010,C#,微信公共平台 程序分2部分,sae部分(处理微信消息),跟桌面部分(查询微信指令,做相应操作)。 实现方法如下
具体实现步骤: 1.注册了个微信公共平台帐号。审核通过后。开启高级功能里面的开发者模式
2.注册sae后上传代码 主要3个文件
3.weixin.php 的关键代码
$wechatObj->valid();
public function valid()
{
$echoStr = $_GET["echostr"];
if($this->checkSignature()){
echo $echoStr;
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;
}
}
微信处理代码
$postStr = $GLOBALS["HTTP_RAW_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 )&&($keyword=="摄像头截图"||$keyword=="屏幕截图")){
$msgType = "text";
$contentStr = "Welcome to wechat world!\n"."你的用户id是:\n".$fromUsername."\n 图片地址:\n"."http://hehe108-pic.stor.sinaapp.com/".$postObj->MsgId.".jpg";
$resultStr = sprintf($textTpl, $fromUsername, $toUsername, $time, $msgType, $contentStr);
$this->saveMsg($postObj->FromUserName,$postObj->CreateTime,$postObj->MsgType,$postObj->Content,$postObj->MsgId);
echo $resultStr;
}else{
$msgType = "text";
$contentStr = "Welcome to wechat world!\n"."你的用户id是:\n".$fromUsername;
$resultStr = sprintf($textTpl, $fromUsername, $toUsername, $time, $msgType, $contentStr);
if($postObj->MsgType=="text")
{
$this->saveMsg($postObj->FromUserName,$postObj->CreateTime,$postObj->MsgType,$postObj->Content,$postObj->MsgId);
}
echo $resultStr;
}
}
query.php关键代码 $mysql = new SaeMysql(); $sql = "SELECT * FROM `weixin` where FromUserName='".$_GET["FromUserName"]."' order by CreateTime desc LIMIT 1"; $data = $mysql->getData( $sql ); echo $data[0]["MsgId"].",".$data[0]["Content"];
$target_path = SAE_TMP_PATH;
$basename=basename( $_FILES['uploadedfile']['name']);
$domain='pic';
$uuid=md5(uniqid(rand(), true));
$target_path = $target_path.$uuid;
if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
} else{
echo "There was an error uploading the file, please try again!";
}
$file_contents= file_get_contents($target_path);
$s = new SaeStorage();
$filename=$_GET["MsgId"].".jpg";
$s->write($domain, $filename ,$file_contents);
5.桌面程序实现
string MsgId = str.Split(',')[0];
StringBuilder sb = new StringBuilder(255);
GetPrivateProfileString("Config", "MsgId", "", sb, sb.Capacity, configpath);
string oldID = sb.ToString();
if (MsgId != oldID)
{
string text = str.Split(',')[1];
WritePrivateProfileString("Config", "MsgId", MsgId, configpath);
ProcessCommand(text, MsgId);
}
c.电脑重启代码
var temp1 = Environment.GetEnvironmentVariable("TEMP");
var picPath1 = string.Format("{0}\\{1}.jpg", temp1, Guid.NewGuid());
Class1.GetScreen(picPath1);
if (File.Exists(picPath1))
Send(picPath1);
var temp = Environment.GetEnvironmentVariable("TEMP");
var picPath = string.Format("{0}\\{1}.jpg", temp, Guid.NewGuid());
Class1.GetCamera(picPath, this.pictureBox1);
if(File.Exists(picPath))
Send(picPath);
break;
public void Send(string file,string MsgId)
{
string ret;
SyncHttp http = new SyncHttp();
List<Parameter> files = new List<Parameter>();
files.Add(new Parameter("uploadedfile", file));
ret = http.HttpPostWithFile("http://hehe108.sinaapp.com/pic.php", "MsgId=" + MsgId, files);
}
代码下载:http://download.csdn.net/detail/xiaoxiao108/5355931
出处:http://www.cnblogs.com/hehe108
|
自学PHP网专注网站建设学习,PHP程序学习,平面设计学习,以及操作系统学习
京ICP备14009008号-1@版权所有www.zixuephp.com
网站声明:本站所有视频,教程都由网友上传,站长收集和分享给大家学习使用,如由牵扯版权问题请联系站长邮箱904561283@qq.com