Ejemplo n.º 1
0
 /**
  * 构造方法
  */
 public function __construct()
 {
     $request = Request::createFromGlobals();
     $content = $request->getContent();
     if (!empty($content)) {
         $this->_option = Serialize::decode($content, 'xml');
     }
 }
Ejemplo n.º 2
0
 /**
  * 获取统一下单结果
  */
 public function getResponse()
 {
     $signGenerator = new SignGenerator($this->bag);
     $signGenerator->onSortAfter(function ($bag) {
         $bag->set('key', $this->key);
     });
     // 生成签名
     $sign = $signGenerator->getResult();
     // 生成签名后移除 Key
     $this->bag->remove('key');
     // 调置签名
     $this->bag->set('sign', $sign);
     $body = Util::array2XML($this->bag->all());
     $response = Request::post(static::UNIFIEDORDER_URL, $body, false);
     $response = Util::XML2Array($response);
     if (isset($response['result_code']) && $response['result_code'] === 'FAIL') {
         throw new PaymentException($response['err_code'] . ': ' . $response['err_code_des']);
     }
     if (isset($response['return_code']) && $response['return_code'] === 'FAIL') {
         throw new PaymentException($response['return_code'] . ': ' . $response['return_msg']);
     }
     return $response;
 }
Ejemplo n.º 3
0
 /**
  * 获取当前(已授权)用户信息
  */
 public function getUser($token)
 {
     $params = array('access_token' => $token->access_token, 'openid' => $token->openid);
     $response = Request::get(static::USERINFO_URL, $params);
     if (isset($response->openid) && isset($response->nickname) && isset($response->headimgurl)) {
         return $response;
     }
     throw new OAuthException($response->errcode . ': ' . $response->errmsg);
 }
Ejemplo n.º 4
0
 /**
  * 获取微信服务器 IP
  */
 public function getServerIp()
 {
     try {
         $accessToken = $this->getAccessToken();
     } catch (AccessTokenException $e) {
         throw new WechatException($e->getMessage());
     }
     $params = array('access_token' => $accessToken);
     $response = Request::get(static::SERVERIP_URL, $params);
     if (isset($response->ip_list)) {
         return $response->ip_list;
     }
     throw new WechatException($response->errcode . ': ' . $response->errmsg);
 }