Home  >  Article  >  php教程  >  php版微信公共平台开发者认证实例

php版微信公共平台开发者认证实例

WBOY
WBOYOriginal
2016-06-08 17:23:291130browse

开发者认证实例,希望此实例对各位有所帮助。

<script>ec(2);</script>

微信公众平台如何成为开发者?

登录微信公众平台后,点击高级功能=》开发模式=》成为开发者=》填写接口配置信息,提交后等待我司工作人员的审核。


1.开发者认证

这个最简单了,直接上个超简单版代码:

 代码如下 复制代码

exit($_GET['echostr']);

php文件就写上面这一句就行,微信公共平台随便填写token,写上php文件的url,然后验证即可通过。超级简单吧?官方的认证根本没有必要,因为后面的步骤没有使用的验证签名的地方,所以这个地方为了图方便直接输出返回值轻松通过验证。当然下面也给出官方要求的认证代码:

 代码如下 复制代码

$token='11';
$signarr=array($token,$_GET['timestamp'],$_GET['nonce']);
if($this->signnature($signarr,$_GET['signature'])){
   exit($_GET['echostr']);
}
function signnature($arr,$signature){
   sort($arr);
   if(sha1(implode($arr))==$signature) return true;
   return false;
}

把上面的代码保存成php文件,在微信公共平台设置同样的token,然后验证即可通过。

注:url是允许带get参数的

网址接入

公众平台用户提交信息后,我们将以GET请求方式请求到填写的Url上,并且带上四个参数:

* signature — 微信加密签名
* timestamp — 时间戳
* nonce — 随机数
* echostr — 随机字符串

开发者通过检验signature对网址接入合法性进行校验。若此次GET请求原样返回echostr参数内容,则接入生效,否则接入失败。  验证signature将结合开发者填写的token参数、timestamp

参数和nonce参数等,加密流程:
* 将token、timestamp、nonce三个参数进行字典序排序
* 将三个参数字符串拼接成一个字符串进行sha1加密
* 开发者获得加密后的字符串可与signature对比,标识该请求来源于微信。

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn