censtart 发表于 2016-7-19 23:45:02

一个微信接口的问题,求高手指点!


<?php
defined('BASEPATH') OR exit('No direct script access allowed');

define("TOKEN", "******");
define("WEIXIN_APPID", "*******");
define("WEIXIN_SECRET", "*******");

class Home extends Home_Controller {

public $CI;
public function __construct() {
                parent::__construct();
               $this->CI = &get_instance();
      
            }
            
      
public function valid()
    {
      $echostr = $this->CI->input->get('echostr');
      if($this->checkSignature()){
            echo $echoStr;
            exit;
      }
    }

    private function checkSignature()
    {
      $signature= $this->CI->input->get('signature');
      $timestamp= $this->CI->input->get('timestamp');
      $nonce      = $this->CI->input->get('nonce');

      $token = TOKEN;
      $tmpArr = array($token, $timestamp, $nonce);
      sort($tmpArr);
      $tmpStr = implode( $tmpArr );
      $tmpStr = sha1( $tmpStr );

      if( $tmpStr == $signature ){
            return true;
      }else{
            return false;
      }
    }

public function index()
    {   
      if (isset($this->CI->input->get['echostr'])) {
    $this->valid();
}else{
    //$wechatObj->responseMsg();
    //$wechatObj->responseMsg2();
    //$wechatObj->responseMsg3();

}




    }
}
1、 填入微信平台URLhttp://www.hzcookie.com/weixin/index.php/home/index/;个人觉得这个地址是不是有问题?

2、2.0直接使用 $_GET,应该是没有问题吧。但好像都获取不到参数?


Hex 发表于 2016-7-20 10:55:53

我写过一个简单例子,你可以参考下 http://codeigniter.org.cn/forums/forum.php?mod=viewthread&tid=16665&extra=page%3D1
页: [1]
查看完整版本: 一个微信接口的问题,求高手指点!