Ejemplo n.º 1
0
 /**
  * 验证配置
  */
 public function validateConfig()
 {
     static $url = 'https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=%s&corpsecret=%s';
     $body = Utility::http(sprintf($url, $this->getConfig('appid'), $this->getConfig('appsecret')));
     $json = json_decode($body, true);
     if (!$json || !empty($json['errcode'])) {
         return false;
     } else {
         return true;
     }
 }
Ejemplo n.º 2
0
 /**
  * 初始化数据
  *
  * @return array|mixed
  */
 public function initialize($xmlData, $replace = true)
 {
     $this->content = $xmlData;
     $xml = @simplexml_load_string($xmlData, 'SimpleXMLElement', LIBXML_NOCDATA | LIBXML_NOBLANKS);
     $params = (array) Utility::extractXML($xml);
     $params += array_change_key_case($params, CASE_LOWER);
     if ($replace) {
         parent::replace($params);
     } else {
         parent::setParameters($params);
     }
 }
Ejemplo n.º 3
0
 /**
  * 获取access_token
  */
 public function getAccessToken()
 {
     static $url = 'https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=%s&corpsecret=%s';
     $token = Utility::getCorpAccessToken($this);
     if (empty($token) || time() > $token['expired']) {
         $body = Utility::http(sprintf($url, $this->getConfig('appid'), $this->getConfig('appsecret')));
         $json = json_decode($body, true);
         if (!$json || !empty($json['errcode'])) {
             throw new Exception('Error - WeChatCorp Can not get AccessToken.');
         } else {
             $token['token'] = $json['access_token'];
             $token['expired'] = time() + $json['expires_in'] - 120;
             Utility::setCorpAccessToken($token, $this);
         }
     }
     return $token['token'];
 }
Ejemplo n.º 4
0
 /**
  * 发送content
  */
 public function send($callback = null)
 {
     if ($callback && is_callable($callback)) {
         $callback($this);
     }
     if (is_array($this->content) || is_object($this->content)) {
         $output = Utility::buildXML((array) $this->content);
     } else {
         $output = (string) $this->content;
     }
     if ($this->encrypted) {
         try {
             $prpcrypt = new Prpcrypt($this->wechat->getConfig('aeskey'));
             $output = $prpcrypt->encrypt($output, $this->wechat->getConfig('appid'));
             $output = $this->encrypt($output);
         } catch (Exception $e) {
         }
     }
     echo $output;
     return $this;
 }
Ejemplo n.º 5
0
 /**
  * 微信JSAPI支付js数据
  * @parameter $res JSAPI下单返回的数组
  */
 public function jsPayConfig($res)
 {
     $data = array('appId' => !empty($res['appid']) ? $res['appid'] : $this->getConfig('appid'), 'timeStamp' => time(), 'nonceStr' => md5(microtime(true)), 'package' => 'prepay_id=' . $res['prepay_id'], 'signType' => 'MD5');
     $data['paySign'] = Utility::getSign($data, $this->getConfig('pay_key'));
     return $data;
 }