Пример #1
0
 /**
  * 构造方法
  */
 public function __construct()
 {
     $request = Request::createFromGlobals();
     $content = $request->getContent();
     if (!empty($content)) {
         $this->_option = Serialize::decode($content, 'xml');
     }
 }
Пример #2
0
 /**
  * 最终输出
  */
 private static function _finalResponse(array $arrayResponse)
 {
     $headers = array('Content-Type' => 'application/xml');
     $response = new Response();
     $response->setHeaders($headers);
     $response->setContent(Serialize::encode($arrayResponse, 'xml'));
     $response->send();
     exit;
 }
Пример #3
0
 /**
  * 获取菜单数据
  */
 public function getData($asJSON = false)
 {
     $data = array('name' => $this->name);
     if ($this->hasChild()) {
         foreach ($this->child as $k => $v) {
             $data['sub_button'][] = $v->getData();
         }
     }
     return $asJSON ? Serialize::encode($data, 'json') : $data;
 }
Пример #4
0
 /**
  * 获取配置文件
  */
 public function getConfig($asArray = false)
 {
     // 下单结果中的 prepay_id
     $response = $this->getResponse();
     $options = array('appId' => $this->wechat['appid'], 'timeStamp' => (string) time(), 'nonceStr' => uniqid(), 'package' => 'prepay_id=' . $response['prepay_id'], 'signType' => 'MD5');
     ksort($options);
     $signature = http_build_query($options);
     $signature = urldecode($signature);
     $signature = strtoupper(md5($signature . '&key=' . $this->wechat['mchkey']));
     $options['paySign'] = $signature;
     return $asArray ? $options : Serialize::encode($options, 'json');
 }
Пример #5
0
 /**
  * 构造方法
  */
 public function __construct()
 {
     $this->content = file_get_contents('php://input');
     if (!empty($this->content)) {
         $data = Serialize::decode($this->content, 'xml');
         try {
             parent::__construct($data);
             $this->valid = true;
         } catch (\InvalidArgumentException $e) {
             $this->error = $e->getMessage();
         }
     }
 }
Пример #6
0
 /**
  * 获取共享收货地址配置
  */
 public function getConfig($asArray = false)
 {
     $protocol = isset($_SERVER['HTTPS']) && ($_SERVER['HTTPS'] !== 'off' || $_SERVER['SERVER_PORT'] == 443) ? 'https://' : 'http://';
     $currentUrl = $protocol . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
     $wechat = $this->accessToken->getWechat();
     $params = array('appid' => $wechat['appid'], 'url' => $currentUrl, 'timestamp' => (string) time(), 'noncestr' => uniqid(), 'accesstoken' => $this->accessToken['access_token']);
     // 按 ASCII 码排序
     ksort($params);
     $addrSign = http_build_query($params);
     $addrSign = urldecode($addrSign);
     $addrSign = sha1($addrSign);
     $config = array('appId' => $params['appid'], 'scope' => 'jsapi_address', 'signType' => 'sha1', 'addrSign' => $addrSign, 'timeStamp' => $params['timestamp'], 'nonceStr' => $params['noncestr']);
     return $asArray ? $config : Serialize::encode($config, 'json');
 }
Пример #7
0
 /**
  * 获取下单结果
  */
 public function getResponse()
 {
     ksort($this->options);
     $signature = http_build_query($this->options);
     $signature = urldecode($signature);
     $signature = strtoupper(md5($signature . '&key=' . $this->wechat['mchkey']));
     $this->options['sign'] = $signature;
     $request = Http::post(self::UNIFIEDORDER_URL, array('body' => Serialize::encode($this->options, 'xml')));
     $response = (array) $request->xml(array('libxml_options' => LIBXML_NOCDATA));
     if (array_key_exists('result_code', $response) && $response['result_code'] === 'FAIL') {
         throw new \Exception($response['err_code'] . ': ' . $response['err_code_des']);
     }
     if (array_key_exists('return_code', $response) && $response['return_code'] === 'FAIL') {
         throw new \Exception($response['return_code'] . ': ' . $response['return_msg']);
     }
     return $response;
 }
Пример #8
0
 /**
  * 获取配置文件
  */
 public function getConfig($asArray = false)
 {
     $wechat = $this->accessToken->getWechat();
     $ticket = $this->ticket->getTicket();
     $protocol = isset($_SERVER['HTTPS']) && ($_SERVER['HTTPS'] !== 'off' || $_SERVER['SERVER_PORT'] == 443) ? 'https://' : 'http://';
     $currentUrl = $protocol . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
     $params = array('jsapi_ticket' => $ticket, 'timestamp' => (string) time(), 'noncestr' => uniqid(), 'url' => $currentUrl);
     // 按 ASCII 码排序
     ksort($params);
     $signature = http_build_query($params);
     $signature = urldecode($signature);
     $signature = sha1($signature);
     $config = array('appId' => $wechat['appid'], 'nonceStr' => $params['noncestr'], 'timestamp' => $params['timestamp'], 'signature' => $signature, 'jsApiList' => $this->api);
     if ($this->debug) {
         $config['debug'] = true;
     }
     return $asArray ? $config : Serialize::encode($config, 'json');
 }
Пример #9
0
 /**
  * 获取实体数据
  */
 public function getData()
 {
     return Serialize::encode($this->options, 'xml');
 }
Пример #10
0
 /**
  * 转为 JSON
  */
 public function toJSON()
 {
     return Serialize::encode($this->toArray(), 'json');
 }
Пример #11
0
 /**
  * 最终输出
  */
 private static function _finalOutput(array $arrayResponse)
 {
     header("Content-Type: application/xml; charset=utf-8");
     echo Serialize::encode($arrayResponse, 'xml');
     exit;
 }
Пример #12
0
 /**
  * 菜单数据
  */
 public function getData($asJSON = false)
 {
     $data = array_merge(array('name' => $this->name, 'type' => $this->type), $this->value);
     return $asJSON ? Serialize::encode($data, 'json') : $data;
 }
Пример #13
0
 /**
  * 获取配置文件
  */
 public function getConfig($asArray = false)
 {
     $options = array('timestamp' => $this->options['timeStamp'], 'nonceStr' => $this->options['nonceStr'], 'package' => $this->options['package'], 'signType' => $this->options['signType'], 'paySign' => $this->generatePaySign());
     return $asArray ? $options : Serialize::encode($options, 'json');
 }
Пример #14
0
 /**
  * 获取配置文件
  */
 public function getConfig($asArray = false)
 {
     $configs = $this->brandWCPayRequest->getConfig(true);
     $options = array('timestamp' => $configs['timeStamp'], 'nonceStr' => $configs['nonceStr'], 'package' => $configs['package'], 'signType' => $configs['signType'], 'paySign' => $configs['paySign']);
     return $asArray ? $options : Serialize::encode($options, 'json');
 }
Пример #15
0
 /**
  * 获取配置文件
  */
 public function getConfig($asArray = false)
 {
     $options = $this->getOptions();
     $options['paySign'] = $this->generatePaySign();
     return $asArray ? $options : Serialize::encode($options, 'json');
 }
Пример #16
0
 /**
  * 发送模板消息
  */
 public function send()
 {
     if (empty($this->options) || $this->options->isEmpty()) {
         throw new \Exception('Options is requried');
     }
     $body = array('touser' => $this->touser, 'template_id' => $this->templateId, 'url' => $this->url, 'data' => $this->options->toArray());
     $request = Http::post(self::SEND_URL, array('body' => Serialize::encode($body, 'json'), 'query' => array('access_token' => $this->accessToken->getAccessToken())));
     $response = $request->json();
     if (array_key_exists('errcode', $response) && $response['errcode'] != 0) {
         throw new \Exception($response['errcode'] . ': ' . $response['errmsg']);
     }
     return $response['msgid'];
 }