wechataccesstoken.php 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <?php
  2. /**
  3. * Created by 上海风车教育科技有限公司.
  4. * User: 刘红伟
  5. * Date: 15-11-24
  6. * Email: 454303753@qq.com
  7. * File:wechataccesstoken.php
  8. */
  9. class wechataccesstoken{
  10. private $appid;
  11. private $secret;
  12. private $_errorno;
  13. private $_error;
  14. public function __construct($appid,$secret)
  15. {
  16. $this->appid=$appid;
  17. $this->secret=$secret;
  18. }
  19. public function get(){
  20. $url="https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=".$this->appid."&secret=".$this->secret;
  21. $http= wx_http::factory($url,wx_http::TYPE_CURL);
  22. $json= $http->get();
  23. $result=json_decode($json,true);
  24. if(isset($result['errcode'])){
  25. $this->_errorno=$result['errcode'];
  26. $this->_error=$result['errmsg'];
  27. return false;
  28. }
  29. if(isset($result['access_token'])){
  30. return $result;
  31. }
  32. }
  33. public function getErrno()
  34. {
  35. return $this->_errno;
  36. }
  37. public function getError()
  38. {
  39. return $this->_error;
  40. }
  41. }