Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class CurlWrap
- {
- private $ch;
- private function setOpts() {
- curl_setopt_array($this->ch, [
- CURLOPT_HEADER => 0,
- CURLOPT_RETURNTRANSFER => true,
- CURLOPT_CONNECTTIMEOUT => 10,
- CURLOPT_TIMEOUT => 10
- ]);
- }
- public function __construct($url = null) {
- $this->ch = curl_init($url);
- }
- public function setUrl($url) {
- curl_setopt($this->ch, CURLOPT_URL, $url);
- }
- public function get() {
- $this->setOpts();
- $result = curl_exec($this->ch);
- if(curl_errno($this->ch)) throw new Exception(curl_error($this->ch));
- return $result;
- }
- public function post($postData) {
- curl_setopt($this->ch, CURLOPT_POSTFIELDS, $postData);
- return $this->get();
- }
- }
- class ConnectGido extends CurlWrap
- {
- public function get() {
- return json_decode(parent::get());
- }
- public function post($postData) {
- return parent::post(json_encode($postData));
- }
- public function login($phone, $password) {
- $this->setUrl('https://test-api.vn/account/login');
- return $this->post(['phone' => $phone, 'password' => $password]);
- }
- }
- $gido = new ConnectGido();
- $result = $gido->login('09843211', '123456');
- print_r($result);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement