java微信开发入门第一讲
来源:互联网 发布:XMLHttpRequest VB方法 编辑:程序博客网 时间:2024/05/16 01:35
微信开发首先必须要有一个web服务器来验证你的信息,所以我们首先要申请一个服务器
1.服务器申请
我们可以的到福佳jsp申请一个php或者Java的空间,申请哪个都可以,不影响使用,我们使用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)){
/* libxml_disable_entity_loader is to prevent XML eXternal Entity Injection,
the best way is to check the validity of xml by yourself */
libxml_disable_entity_loader(true);
$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()
{
// you must define TOKEN by yourself
if (!defined("TOKEN")) {
throw new Exception('TOKEN is not defined!');
}
$signature = $_GET["signature"];
$timestamp = $_GET["timestamp"];
$nonce = $_GET["nonce"];
$token = TOKEN;
$tmpArr = array($token, $timestamp, $nonce);
// use SORT_STRING rule
sort($tmpArr, SORT_STRING);
$tmpStr = implode( $tmpArr );
$tmpStr = sha1( $tmpStr );
if( $tmpStr == $signature ){
return true;
}else{
return false;
}
}
}
?>
2.申请微信公众平台测试账号
打开浏览器,这里以IE为例。输入:http://mp.weixin.qq.com/debug/cgi-bin/sandbox?t=sandbox/login
填写配置信息
这样环境就配置好了,接下来我们可以编写代码了
- java微信开发入门第一讲
- 微信服务号开发系列培训第一讲 服务号如何连接Java Web应用
- Java微信开发入门
- Java微信开发入门
- 第一讲 Objective-C开发入门
- 微信视频公开课第一讲
- JAVA微信公众号开发入门
- [049] 微信公众平台开发视频公开课第1讲-基础入门
- 微信公众平台开发视频公开课第1讲-基础入门
- [049] 微信公众平台开发视频公开课第1讲-基础入门
- 微信公众平台开发视频公开课第1讲-基础入门
- 微信开发入门
- 微信开发入门
- 微信开发入门
- 微信开发入门
- 微信开发入门
- 微信入门开发
- 微信开发入门
- 课堂笔记四月十三日
- 计算机视觉基础2——相机成像的几何描述
- vi 选择复制
- TCP 连接状态
- 如何在Windows环境下的VS中安装使用Google Protobuf完成SOCKET通信
- java微信开发入门第一讲
- 语音识别common1(音素,三音素)
- git操作指令
- 计算机视觉基础3——内部参数描述
- Android中JSON数据解析:系统自带JSONObject以及第三方GSON的实现
- 第八届蓝桥杯k倍区间
- 放开了跑,没有退路
- R语言连接数据库
- 关于Servlet补充知识点