php 开发微信,php微信开发01

/**

* wechat php test

*/

//define your token

define("TOKEN", "weixin");

$wechatObj = new wechatCallbackapiTest();

//$wechatObj->valid();

$wechatObj->responseMsg();

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();

$type=$postObj->MsgType;

$customevent=$postObj->Event;

$latitude=$postObj->Location_X;

$longitude=$postObj->Location_Y;

$textTpl = "

%s

0

";

//发送位置回复

if($type=="location"){

$contentStr="你的纬度是($latitude),经度是($longitude),我已经锁定!";

$msgType = "text";

$resultStr = sprintf($textTpl, $fromUsername, $toUsername, $time, $msgType, $contentStr);

echo $resultStr;

}

//关键字回复

if(!empty( $keyword ))

{

$msgType = "text";

if($keyword=="1") {

$contentStr = "感谢关注泛IT!";}

if($keyword=="2") {

$contentStr = "联系QQ:,欢迎投稿以及提出宝贵意见";}

if($keyword=="3") {

$contentStr = "你的图片不错,还是输入文字吧!";}

$resultStr = sprintf($textTpl, $fromUsername, $toUsername, $time, $msgType, $contentStr);

echo $resultStr;

}else{

echo "Input something...";

}

//关注公众号后回复

if($type="event" and $customevent="subscribe"){

$contentStr="感谢关注泛IT\n您可以分别回复1、2、3";

$msgType = "text";

$resultStr = sprintf($textTpl, $fromUsername, $toUsername, $time, $msgType, $contentStr);

echo $resultStr;

}

//图片回复

if($type="image"){

$contentStr="你的图片很棒!";

$msgType = "text";

$resultStr = sprintf($textTpl, $fromUsername, $toUsername, $time, $msgType, $contentStr);

echo $resultStr;

}

//switch语句优化

 /*

switch($type)

{

//处理文本

case "text":

//关键字回复

if(!empty( $keyword ))

{

//$msgType = "text";

if($keyword=="1") {

$contentStr = "回复1查看使用说明\n回复2查看联系方式\n回复3使用翻译字典\n回复4使用机器人聊天功能";}

if($keyword=="2") {

$contentStr = "联系QQ:,欢迎投稿以及提出宝贵意见";}

}else{

$contentStr="此项功能尚未开发"; }

break;

//处理图片信息

case "image":

$contentStr="你的图片不错,还是输入文字吧";

break;

//处理位置信息

case "location":

$contentStr="你的纬度是($latitude),经度是($longitude),我已经锁定!";

break;

//处理关注事件

case "event":

if($customevent=="subscribe")

{$contentStr="感谢关注泛IT\n回复1查看使用说明";}

break;

default:

$contentStr="此项功能尚未开发";

}

$msgType = "text";

$resultStr=sprintf($textTpl,$fromUsername,$toUsername,$time,$msgType,$contentStr);

echo $resultStr;

*/

}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 rulesort($tmpArr, SORT_STRING);$tmpStr = implode( $tmpArr );$tmpStr = sha1( $tmpStr );if( $tmpStr == $signature ){return true;}else{return false;}}}?>

2018最新微信微信上墙婚庆会议大屏幕3D签到抽奖摇一摇微信上墙源码。这是我在淘宝上面花了200大洋买的,php版本5.4以上,亲测可用,上墙,抽奖,摇一摇。都可以使用。绝对没有问题。之前在网上花了2天时间也找了一些类似的,有免费下载的,也有包括在csdn上面用5个资源分下载类似的,发现都不能用,至少我在本地或有服务器上都没有调试成功,看了一下他们的代码,发现代码用的是公众号帐号和密码,来模拟微信登陆来获取用户信息。微信已经在2016年就已经停止模似登陆了,登陆微信公众号,必须要扫描后,管理员确认后才可登陆。所以,那些代码都不能用。有些有csdn上传的这些代码基本上不能用(可能2015年前可以用,但是现在不能用),感觉太不负责任了,都是骗积分的。当时因为公司年会要弄个微信上墙及现在抽奖活动,找这个代码也很辛苦,相信大家也一样辛苦,所以,把代码放出来,供大家下载学习使用。这个代码,我是在淘宝上买的,本身内置了第三方的微信公众号授权,所以,如果你的公众号没有微信认证也可以用,直接扫码就可以发送微信上墙弹幕,不会出现第三方公众号信息。如果你的微信公众号认证了,就用自己的,后台可以配置,填写你的公众号appid和appsecret即可。好了,不多说了,大家下 载使用,如果不能用,我退积分。不清楚的,大家可以在评论区留言。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值