源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

微信小程序url与token设置详解

  • 时间:2022-03-29 12:40 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要:微信小程序url与token设置详解
[b]微信小程序url与token设置详解[/b] 新浪云应用sae的代码里创建一个weixin.php文件,写入以下代码
define("TOKEN","myToken");// 后台填写的token,在微信公众平台启用
$wechatObj = new wechatAPI();
$wechatObj->isValid();
class wechatAPI
{
  public function isValid()//验证微信接口,验证函数以外的代码和微信公众号开发token设置相同
  {
     $echoStr = $_GET["echostr"];
     if ($this->checkSignature()) {
       header('content-type:text');//add,一定要加入header
      echo $echoStr;
      exit;
     }
  }
  private function checkSignature()  //官方的验证函数
  {
     $signature = $_GET["signature"];
     $timestamp = $_GET["timestamp"];
     $nonce = $_GET["nonce"];
     $token = TOKEN;
     $tmpArr = array($token, $timestamp, $nonce);
     sort($tmpArr, SORT_STRING);
     $tmpStr = implode( $tmpArr );
     $tmpStr = sha1( $tmpStr );
     if( $tmpStr == $signature ){
      return true;
     }else{
      return false;
     }
  }
};
保存后通过url访问,在地址栏复制url,写入微信公众平台中 [img]http://files.jb51.net/file_images/article/201709/2017926145539244.jpg?2017826145554[/img] 在微信公众平台的开发设置中,填入以上获得的url和设置的token,自动生成EncodingASEKey [img]http://files.jb51.net/file_images/article/201709/2017926145602093.jpg?2017826145618[/img] 设置完成 [img]http://files.jb51.net/file_images/article/201709/2017926145626971.jpg?2017826145639[/img] 如有疑问请留言或者到本站社区交流讨论,感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!
  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部