TP5结合微信公众号学习笔记一(入门篇)

前言:
首先,根据比赛的业务需求,需要实现微信网页授权登入、以及模板消息发送等功能,小程序 并不能熟悉使用

前期准备:
在微信公众平台注册 并登陆,配置好开发环境;

建议:
新手 最好先看看网上一些现成的代码,理想的的话最好可以跟着视频学习 或者有人带:
配置环境:

WexChat.php 下的index方法:
 

public function index(){
		$echostr = input('echostr/s','');
		if(empty($echostr)){
			$this->reponseMsg();
		}
		else{
			//获得参数 signature nonce token timestamp echostr
		$nonce     = input('nonce');
		$token     = 'slwision';
		$timestamp = input('timestamp');
		$echostr   = input('echostr');
		$signature = input('signature');
		//形成数组,然后按字典序排序
		$array = array();
		$array = array($nonce, $timestamp, $token);
		sort($array);
		//拼接成字符串,sha1加密 ,然后与signature进行校验
		$str = sha1( implode('',$array));
			if( $str  == $signature && $echostr ){
			//第一次接入weixin api接口的时候
			echo  $echostr;
			exit;
		   }
		}
	}

注意:
提交个两三次 如果还是不行 在修改一下 Token 的值,因为可能以前用过 现在再用重复了

猜你喜欢

转载自blog.csdn.net/qq_37457202/article/details/87024704