Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- defined('BASEPATH') or exit('No direct script access allowed');
- require APPPATH . '/libraries/REST_Controller.php';
- require '/home/digipos.gatewize.com/public_html/vendor/autoload.php';
- use Restserver\Libraries\REST_Controller;
- use Psr\Http\Message\ResponseInterface;
- use GuzzleHttp\Exception\RequestException;
- use GuzzleHttp\Client;
- use GuzzleHttp\Cookie\CookieJar;
- use GuzzleHttp\Middleware;
- use GuzzleHttp\Pool;
- use GuzzleHttp\Promise\EachPromise;
- use GuzzleHttp\Psr7\Request;
- use GuzzleHttp\HandlerStack;
- class Digipos extends REST_Controller
- {
- public $activeUser = null;
- public $client = null;
- public $appVersion = "2.5.9";
- function __construct()
- {
- parent::__construct();
- date_default_timezone_set('Asia/Jakarta');
- $this
- ->parser
- ->setModule("api");
- $this->activeUser = $this->check_user();
- if ($this->client == null) $this->client = new Client([
- 'base_uri' => 'https://digipos.telkomsel.com/api/',
- 'timeout' => 150,
- 'connection_timeout' => 100,
- 'headers' => [
- 'User-Agent' => 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36',
- 'Accept' => 'application/json, text/javascript, */*;;q=0.8',
- 'Accept-Encoding' => 'gzip, deflate, br'
- ],
- 'verify' => false
- ]);
- }
- private function check_user()
- {
- $license = $this
- ->uri
- ->segment(4);
- $user = $this
- ->user_m
- ->get_by('license_key', $license);
- if (is_null($user) && !($user->expired_date >= date("Y-m-d"))) die(json_encode(array(
- "status" => false,
- "status_code" => "ERR-001",
- "message" => "License is not Valid or Expired"
- )));
- else return $user;
- }
- public function index_get()
- {
- echo "@STATUS:GAGAL@MESSAGE:URL ANDA SALAH@";
- }
- public function index_post()
- {
- echo "@STATUS:GAGAL@MESSAGE:URL ANDA SALAH@";
- }
- /** DIGIPOS MAIN FUNCTION **/
- public function doLogin($license = "", $password = "")
- {
- $username = $this->activeUser->username;
- $password = "666" . md5($password);
- if ($this->activeUser->autotp == 1){
- $loginResp = $this->guzzLogin($username, $password);
- if ($loginResp->status){
- return $loginResp->data;
- } else {
- return $loginResp;
- }
- } else {
- return (object)array(
- "status" => false,
- "status_code" => "ERR-015",
- "message" => "Fitur AutOTP disabled. Silahkan upgrade user anda!"
- );
- }
- }
- public function verifyOtp($license = "", $token = "", $otp = "")
- {
- $otpResp = $this->guzzLoginOtp($token, $otp);
- if ($otpResp->status)
- {
- $token = $otpResp->token;
- $decrypt = shell_exec("node /home/digipos.gatewize.com/public_html/node_lib/decrypt.js " . $token);
- $decrypt = explode("|", $decrypt);
- $loginData = $otpResp->data;
- $userId = $loginData
- ->data
- ->user->userId;
- $userCode = $loginData
- ->data
- ->user->code;
- $rsNumber = $loginData
- ->data
- ->user
- ->rsOutlet->rsNumber;
- $profile = $this->guzzProfile($userCode, $token);
- $updateId = $this
- ->user_m
- ->update($this
- ->activeUser->id, array(
- 'outlet_id' => $profile
- ->data
- ->outlet->outletId,
- 'token' => $decrypt[0],
- 'data_login' => json_encode($loginData)
- ));
- return $this
- ->user_m
- ->get($this
- ->activeUser
- ->id);
- }
- else return $otpResp;
- }
- public function getProduct($tipe = "", $tujuan = "082136333348")
- {
- $trxType = $this->parseTipeProduk($tipe);
- $token = $this->activeUser->token;
- $token = shell_exec("node /home/digipos.gatewize.com/public_html/node_lib/jwt.js " . $token);
- $outletId = $this->activeUser->outlet_id;
- if($trxType != "VF") {
- $brand = $this->guzzItem("brand", $tujuan, $token);
- $product = $this->guzzProduct($trxType, $tujuan, $brand->data, $outletId, $token);
- } else {
- $product = $this->guzzProductVoucher($token);
- }
- return $product;
- }
- public function getReport($startDate = "", $endDate = "")
- {
- if ($startDate == "") $startDate = date("Ymd");
- if ($endDate == "") $endDate = date("Ymd");
- $username = $this
- ->activeUser->username;
- $token = $this
- ->activeUser->token;
- $token = shell_exec("node /home/digipos.gatewize.com/public_html/node_lib/jwt.js " . $token);
- $loginData = json_decode($this
- ->activeUser
- ->data_login);
- $userId = $loginData
- ->data
- ->user->userId;
- $userCode = $loginData
- ->data
- ->user->code;
- $rsNumber = $loginData
- ->data
- ->user
- ->rsOutlet->rsNumber;
- $report = $this->guzzReport($startDate, $endDate, $userId, $rsNumber, $token);
- return $report;
- }
- public function getVoucherReport($startDate = "", $endDate = "")
- {
- if ($startDate == "") $startDate = date("Ymd");
- if ($endDate == "") $endDate = date("Ymd");
- $username = $this
- ->activeUser->username;
- $token = $this
- ->activeUser->token;
- $token = shell_exec("node /home/digipos.gatewize.com/public_html/node_lib/jwt.js " . $token);
- $loginData = json_decode($this
- ->activeUser
- ->data_login);
- $userId = $loginData
- ->data
- ->user->userId;
- $userCode = $loginData
- ->data
- ->user->code;
- $rsNumber = $loginData
- ->data
- ->user
- ->rsOutlet->rsNumber;
- $report = $this->guzzVoucherReport($startDate, $endDate, $userId, $rsNumber, $token);
- return $report;
- }
- public function getRechargeReport($startDate = "", $endDate = "")
- {
- if ($startDate == "") $startDate = date("Ymd");
- if ($endDate == "") $endDate = date("Ymd");
- $username = $this
- ->activeUser->username;
- $token = $this
- ->activeUser->token;
- $token = shell_exec("node /home/digipos.gatewize.com/public_html/node_lib/jwt.js " . $token);
- $loginData = json_decode($this
- ->activeUser
- ->data_login);
- $userId = $loginData
- ->data
- ->user->userId;
- $userCode = $loginData
- ->data
- ->user->code;
- $rsNumber = $loginData
- ->data
- ->user
- ->rsOutlet->rsNumber;
- $report = $this->guzzRechargeReport($startDate, $endDate, $userId, $rsNumber, $token);
- return $report;
- }
- public function cekProduk($produk, $tujuan,$idTrx) {
- $bulkProduct = $this->getProduct("bulk", $tujuan);
- if ($bulkProduct->status) {
- $product = null;
- $trxType = "AP_BULK";
- if (is_numeric($produk)) {
- $product = $this->product_m->get_by(array('product_id' => $produk));
- $trxType = $product->product_cat;
- }
- else {
- foreach ($bulkProduct->data->list as $key => $value)
- {
- $productName = str_replace(" ", "", str_replace("/", "X", $value->productName));
- if (strpos(strtolower(trim($productName)) , strtolower(trim($produk))) !== false)
- {
- $product = $value;
- $product->product_id = $product->productId;
- unset($product->productId);
- break;
- }
- }
- }
- if (!is_null($product)) {
- $token = $this->activeUser->token;
- $token = shell_exec("node /home/digipos.gatewize.com/public_html/node_lib/jwt.js " . $token);
- $loginData = json_decode($this->activeUser->data_login);
- $userId = $loginData->data->user->userId;
- $userCode = $loginData->data->user->code;
- $rsNumber = $loginData->data->user->rsOutlet->rsNumber;
- $outletId = $this->activeUser->outlet_id;
- $segment = $this->guzzItem("segment", $tujuan, $token);
- $productId = $product->product_id;
- if ($segment->status) {
- $los = $segment->data->los[0];
- }
- $harga = $this->guzzProductErin($tujuan, $productId, $rsNumber, $trxType, $token);
- if ($harga->status) {
- $nominal = $harga->data->nominal;
- $quota = $harga->data->quota;
- $validity = $harga->data->validity;
- $msg = "@STATUS:OK@MSISDN:".$tujuan."@HARGA:".$nominal."@KODE:".$produk."@PRODUK:".$quota . " / " . $validity . " hari"."@LOS:".$los."@";
- return (object)array("status" => true, "status_code" => "OK", "message" => $msg);
- } else {
- //gagal
- $msg = "@STATUS:GAGAL@MSISDN:".$tujuan."@MESSAGE:Gagal Inquiry Harga@KODE:ERR-016@";
- return (object)array("status" => false, "status_code" => "ERR-009", "message" => $msg);
- }
- }
- } else {
- if(strpos($bulkProduct->message, 'Token Expired') !== false) {
- $msg = "@MSISDN:".$tujuan."@STATUS:GAGAL@MESSAGE:TOKEN / OTP EXPIRED@KET:".$produk."@IDTRX:".$idTrx."@";
- return (object) array("status" => "GAGAL", "status_code" => "ERR-010", "message" => $msg);
- } else {
- $msg = "@MSISDN:".$tujuan."@STATUS:GAGAL@MESSAGE:".$bulkProduct->message."@KET:".$produk."@IDTRX:".$idTrx."@";
- return (object) array("status" => "GAGAL", "status_code" => "ERR-011", "message" => $msg);
- }
- }
- }
- public function topupVoucher($pin = "", $produk = "", $tujuan = "", $idTrx = "")
- {
- $transaction = $this->transaction_m->get_by(array('trxserverid'=>$idTrx, 'id_user' => $this->activeUser->id));
- if (is_null($transaction)){
- //get product bulk
- $bulkProduct = $this->getProduct("voucher", $tujuan);
- if ($bulkProduct->status){
- $product = null;
- foreach ($bulkProduct->data->list as $key => $value){
- $productName = str_replace(" ", "", str_replace("/", "X", $value->productName));
- if (strpos(strtolower(trim($productName)) , strtolower(trim($produk))) !== false){
- $product = $value;
- $product->product_id = $product->productId;
- unset($product->productId);
- break;
- }
- }
- if (!is_null($product)) {
- //product ditemukan
- $token = $this->activeUser->token;
- $token = shell_exec("node /home/digipos.gatewize.com/public_html/node_lib/jwt.js " . $token);
- $loginData = json_decode($this->activeUser->data_login);
- $userId = $loginData->data->user->userId;
- $userCode = $loginData->data->user->code;
- $rsNumber = $loginData->data->user->rsOutlet->rsNumber;
- $outletId = $this->activeUser->outlet_id;
- $productId = $product->product_id;
- $validate = $this->guzzValidateVoucher($tujuan, $token);
- if($validate->status) {
- //voucher validated
- $detail = $this->guzzVoucherErin($productId, $token);
- if($detail->status){
- $productDesc = $detail->data->productDesc;
- $nominal = $detail->data->nominal;
- // $insertId = $this->transaction_m->insert(array(
- // 'msisdn' => $tujuan,
- // 'trxserverid' => $idTrx,
- // 'id_user' => $this->activeUser->id,
- // 'productId' => $productId,
- // 'harga' => $nominal,
- // 'message' => '',
- // 'status_code' => 'DIGI-000',
- // 'status' => 'PROSES'
- // ));
- $topup = $this->guzzVoucherBeli($pin, $productId, $tujuan, $token);
- var_dump($topup);
- } else {
- }
- } else {
- //voucher not validated
- }
- } else {
- $msg = "@MSISDN:".$tujuan."@STATUS:GAGAL@MESSAGE:PRODUK TIDAK DITEMUKAN@KET:".$produk."@IDTRX:".$idTrx."@";
- return (object)array("status" => false, "status_code" => "ERR-004", "message" => $msg);
- }
- } else {
- //error atau session habis
- if(strpos($bulkProduct->message, 'Token Expired') !== false) {
- $msg = "@MSISDN:".$tujuan."@STATUS:SUSPECT@MESSAGE:TOKEN / OTP EXPIRED@KET:".$produk."@IDTRX:".$idTrx."@";
- return (object) array("status" => "GAGAL", "status_code" => "ERR-010", "message" => $msg);
- } else {
- $msg = "@MSISDN:".$tujuan."@STATUS:SUSPECT@MESSAGE:".$bulkProduct->message."@KET:".$produk."@IDTRX:".$idTrx."@";
- return (object) array("status" => "GAGAL", "status_code" => "ERR-011", "message" => $msg);
- }
- }
- } else {
- //transaksi ada
- $msg = "@MSISDN:".$tujuan."@MESSAGE:TRANSAKSI TELAH DILAKUKAN@KET:".$produk."@".$transaction->message."@";
- return (object) array("status" => false, "message" => $msg, "status_code" => "ERR-015");
- }
- }
- public function beliProduk($pin = "", $limitHarga = "", $limitLos = "", $produk = "", $tujuan = "", $idTrx = "")
- {
- $transaction = $this->transaction_m->get_by(array('trxserverid'=>$idTrx, 'id_user' => $this->activeUser->id));
- if (is_null($transaction)){
- //get product bulk
- $bulkProduct = $this->getProduct("bulk", $tujuan);
- if ($bulkProduct->status){
- $product = null;
- $trxType = "AP_BULK";
- if (is_numeric($produk)){
- //bukan bulk
- $product = $this
- ->product_m
- ->get_by(array(
- 'product_id' => $produk
- ));
- $trxType = $product->product_cat;
- } else {
- //bulk
- foreach ($bulkProduct->data->list as $key => $value){
- $productName = str_replace(" ", "", str_replace("/", "X", $value->productName));
- if (strpos(strtolower(trim($productName)) , strtolower(trim($produk))) !== false){
- $product = $value;
- $product->product_id = $product->productId;
- unset($product->productId);
- break;
- }
- }
- }
- if (!is_null($product)) {
- //product ditemukan
- $token = $this->activeUser->token;
- $token = shell_exec("node /home/digipos.gatewize.com/public_html/node_lib/jwt.js " . $token);
- $loginData = json_decode($this->activeUser->data_login);
- $userId = $loginData->data->user->userId;
- $userCode = $loginData->data->user->code;
- $rsNumber = $loginData->data->user->rsOutlet->rsNumber;
- $outletId = $this->activeUser->outlet_id;
- $productId = $product->product_id;
- //jika los < 0, bypass segment.
- $los = -1;
- if(intval($limitLos) > 0) {
- $segment = $this->guzzItem("segment", $tujuan, $token);
- if ($segment->status){
- $los = $segment->data->los[0];
- $los = ($los > 0) ? $los : -1;
- }
- }
- if ($los == -1 || intval($los) >= intval($limitLos)){
- $harga = $this->guzzProductErin($tujuan, $productId, $rsNumber, $trxType, $token);
- if ($harga->status){
- $nominal = $harga->data->nominal;
- $quota = $harga->data->quota;
- $validity = $harga->data->validity;
- if (intval($nominal) <= intval($limitHarga)){
- $insertId = $this->transaction_m->insert(array(
- 'msisdn' => $tujuan,
- 'trxserverid' => $idTrx,
- 'id_user' => $this->activeUser->id,
- 'productId' => $productId,
- 'harga' => $nominal,
- 'message' => '',
- 'status_code' => 'DIGI-000',
- 'status' => 'PROSES'
- ));
- $data = $this->aktivasiProduk([$quota, $validity], $insertId, $idTrx, $los, $nominal, $pin, $tujuan, $productId, $rsNumber, $userId, $outletId, $token);
- return $data;
- } else {
- $msg = "@MSISDN:".$tujuan."@STATUS:GAGAL@MESSAGE:HARGALEBIH BESAR DARI LIMIT HARGA REQUEST@KET:".$produk."@IDTRX:".$idTrx."@";
- return (object)array("status" => false, "status_code" => "ERR-006", "message" => $msg);
- }
- } else {
- $msg = "@MSISDN:".$tujuan."@STATUS:GAGAL@MESSAGE:PRODUK TIDAK DITEMUKAN@KET:".$produk."@IDTRX:".$idTrx."@";
- return (object)array("status" => false, "status_code" => "ERR-004", "message" => $msg);
- }
- } else {
- $msg = "@MSISDN:".$tujuan."@STATUS:GAGAL@MESSAGE:LOS LEBIH KECIL DARIPADA LIMIT LOS@KET:".$produk."@IDTRX:".$idTrx."@";
- return (object)array("status" => false, "status_code" => "ERR-004", "message" => $msg);
- }
- } else {
- $msg = "@MSISDN:".$tujuan."@STATUS:GAGAL@MESSAGE:PRODUK TIDAK DITEMUKAN@KET:".$produk."@IDTRX:".$idTrx."@";
- return (object)array("status" => false, "status_code" => "ERR-004", "message" => $msg);
- }
- } else {
- //error atau session habis
- if(strpos($bulkProduct->message, 'Token Expired') !== false) {
- $msg = "@MSISDN:".$tujuan."@STATUS:SUSPECT@MESSAGE:TOKEN / OTP EXPIRED@KET:".$produk."@IDTRX:".$idTrx."@";
- return (object) array("status" => "GAGAL", "status_code" => "ERR-010", "message" => $msg);
- } else {
- $msg = "@MSISDN:".$tujuan."@STATUS:SUSPECT@MESSAGE:".$bulkProduct->message."@KET:".$produk."@IDTRX:".$idTrx."@";
- return (object) array("status" => "GAGAL", "status_code" => "ERR-011", "message" => $msg);
- }
- }
- } else {
- //transaksi ada
- $msg = "@MSISDN:".$tujuan."@MESSAGE:TRANSAKSI TELAH DILAKUKAN@KET:".$produk."@".$transaction->message."@";
- return (object) array("status" => false, "message" => $msg, "status_code" => "ERR-015");
- }
- }
- public function aktivasiProduk($item, $insertId, $idTrx, $los, $harga, $pin, $tujuan, $productId, $rsNumber, $userId, $outletId, $token)
- {
- $todayDate = date("Ymd");
- $buyProduct = $this->guzzAktivasiPaket($harga, $pin, $tujuan, $productId, $rsNumber, $userId, $outletId, $token);
- if ($buyProduct->status){
- sleep(10);
- $report = $this->guzzReport($todayDate, $todayDate, $userId, $rsNumber, $token);
- if($report->status) {
- sleep(3);
- $filtered_report = $this->searchReport($report->data, $tujuan, $productId);
- if(!is_null($filtered_report)) {
- if(strcasecmp($filtered_report->status,"SUKSES") == 0) {
- $stok = $this->guzzProductMkios($rsNumber, $pin, $outletId, $token);
- $total = $stok->data->total;
- $bulk = $stok->data->list[6]->inventoryTransactionResult->inventory;
- $sn = $filtered_report->serialNumber;
- $extTrxId = $filtered_report->extTrxId;
- $sn = !is_null($sn) ? "1".$sn : substr($extTrxId, 4);
- $msisdn = $filtered_report->msisdn;
- $status = $filtered_report->status;
- $id = $filtered_report->id;
- $cashbackStatus = $filtered_report->id;
- $statusDesc = $filtered_report->statusDesc;
- $msg = "@SN:".$sn."@MSISDN:".$msisdn."@STATUS:".$status."@ID:".$id."@CASHBACKSTS:".$cashbackStatus."@STATUSDESC:".$statusDesc."@LOS:".$los."@HARGA:".$harga."@PRODUK:" . $item[0] . "/" . $item[1] . " hari" ."@SALDO:".$bulk."@TOTALSALDO:".$total."@"."IDTRX:".$idTrx."@";
- $resp = array("status" => "SUKSES", "status_code" => "OK", "message" => $msg, "harga" => $harga, "los" => $los, "idtrx" => $idTrx);
- } else if(strpos($filtered_report->statusDesc, 'XML Frontend Halted') !== false) {
- $msg = "@MSISDN:".$tujuan."@STATUS:SUSPECT@MESSAGE:TRANSAKSI PENDING@KET:CEK WEB REPORT@IDTRX:".$idTrx."@";
- $resp = array("status" => "SUSPECT", "status_code" => "ERR-008", "message" => $msg, "harga" => $harga, "los" => $los, "idtrx" => $idTrx);
- } else if((strcasecmp($filtered_report->status, "GAGAL") == 0
- || strpos($filtered_report->statusDesc, 'location') !== false
- || strpos($filtered_report->statusDesc, 'stockNotEnough') !== false
- || strpos($filtered_report->statusDesc, 'postPaidNumber') !== false
- || strpos($filtered_report->statusDesc, 'subsTypeNotDefined') !== false
- || strpos($filtered_report->statusDesc, 'error while checking balance') !== false
- || strpos($filtered_report->statusDesc, 'pinIncorrect') !== false
- || strpos($filtered_report->statusDesc, 'recharge split code failed') !== false
- )){
- $msg = "@MSISDN:".$tujuan."@STATUS:GAGAL@MESSAGE:TRANSAKSI GAGAL@KET:".$filtered_report->statusDesc."@IDTRX:".$idTrx."@";
- $resp = array("status" => "GAGAL", "status_code" => "ERR-007", "message" => $msg, "harga" => $harga, "los" => $los, "idtrx" => $idTrx);
- } else {
- $msg = "@MSISDN:".$tujuan."@STATUS:SUSPECT@MESSAGE:TRANSAKSI PENDING@KET:CEK WEB REPORT@IDTRX:".$idTrx."@";
- $resp = array("status" => "SUSPECT", "status_code" => "ERR-008", "message" => $msg, "harga" => $harga, "los" => $los, "idtrx" => $idTrx);
- }
- } else {
- $msg = "@MSISDN:".$tujuan."@STATUS:GAGAL@MESSAGE:TRANSAKSI GAGALT@KET:CEK WEB REPORT@IDTRX:".$idTrx."@";
- $resp = array("status" => "GAGAL", "status_code" => "ERR-007", "message" => $msg, "harga" => $harga, "los" => $los, "idtrx" => $idTrx);
- }
- } else {
- //failed to get report
- $msg = "@MSISDN:".$tujuan."@STATUS:SUSPECT@MESSAGE:TRANSAKSI PENDING@KET:CEK WEB REPORT@IDTRX:".$idTrx."@";
- $resp = array("status" => "SUSPECT", "status_code" => "ERR-008", "message" => $msg, "harga" => $harga, "los" => $los, "idtrx" => $idTrx);
- }
- $this->transaction_m->update($insertId, array('status' => $resp['status'], "message" => $resp['message'], "status_code" => $resp['status_code']));
- return $this->transaction_m->get($insertId);
- } else {
- $msg = "@MSISDN:" . $tujuan . "@STATUS:GAGAL@MESSAGE:" . $buyProduct->message . "@KET:" . $produk . "@IDTRX:" . $idTrx . "@";
- return (object)array(
- "status" => false,
- "status_code" => "ERR-012",
- "message" => $msg
- );
- $this->transaction_m->update($insertId, array('status' => $resp['status'], "message" => $resp['message'], "status_code" => $resp['status_code']));
- return $this->transaction_m->get($insertId);
- }
- }
- public function test()
- {
- // $token = $this->activeUser->token;
- // $token = shell_exec("node /home/digipos.gatewize.com/public_html/node_lib/jwt.js " . $token);
- // $code = $this->activeUser->username;
- // $profile = $this->guzzProfile($code, $token);
- // $data = $this->getRechargeReport("","");
- $data = $this->getProduct("bulk", "082136333348");
- var_dump($data);
- }
- public function testSession()
- {
- $token = $this
- ->activeUser->token;
- $token = shell_exec("node /home/digipos.gatewize.com/public_html/node_lib/jwt.js " . $token);
- echo $token;
- $client = new Client();
- $promise = $client->requestAsync('GET', 'https://digipos.telkomsel.com/outapp/dashboard', ['headers' => ['Authorization' => 'Bearer ' . $token]]);
- $response = $promise->wait();
- echo $response->getBody()
- ->getContents();
- }
- /** DIGIPOS GUZZLE FUNCTION **/
- public function guzzSmof()
- {
- $client = new Client(['headers' => ['User-Agent' => 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36', 'Accept' => 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8', 'Accept-Encoding' => 'gzip, deflate, br', ]]);
- try
- {
- $promise = $client->requestAsync('POST', 'https://digipos.telkomsel.com/mwa/Smof?', ['form_params' => ['media' => '1', 'activity' => '', 'outletid' => '', 'userid' => '', 'pin' => '', 'capcha' => '', 'lac' => 'lac_wb', 'ci' => 'ci_wb', 'lat' => '-1', 'lng' => '-1', 'mcc' => 'mcc_wb', 'mnc' => 'mnc_wb', 'imei' => '-1', 'iccid' => 'iccid-web', 'lastid' => '0', 'limit' => '10', 'procid' => 'ua', 'proccode' => 'ua-10', 'usercode' => 'AND7571037', 'xid' => '44556677884', 'password' => '583' . md5('123321') , 'version' => 'MO-05']]);
- $response = $promise->wait();
- $data = json_decode($response->getBody()
- ->getContents());
- echo $response->getBody()
- ->getContents();
- echo "test";
- var_dump($data);
- //{"response":"200 OK","error_code":"200 OK"}
- //GET COOKIE
- }
- catch(\Exception $e)
- {
- //throw exception
- var_dump($e);
- echo "error";
- }
- }
- public function guzzLogin($username, $password)
- {
- try
- {
- $promise = $this
- ->client
- ->requestAsync('POST', 'user/auth', ['form_params' => ['username' => $username, 'password' => $password, 'isBrowser' => true, 'browser' => 'Firefox', 'browserVersion' => '61.0', 'osVersion' => '10.0', 'appVersion' => $this->appVersion, 'karyawan' => true, 'os' => 'MAC OS']]);
- $response = $promise->wait();
- // var_dump($response);
- $data = json_decode($response->getBody()
- ->getContents());
- if ($response->getStatusCode() == 200 && $data->status == 0)
- {
- return (object)array(
- "status" => true,
- "status_code" => "OK",
- "data" => $data
- );
- }
- else
- {
- return (object)array(
- "status" => false,
- "status_code" => "ERR-001",
- "message" => $data->message
- );
- }
- }
- catch(\Exception $e)
- {
- //do nothing
- $data = json_decode($e->getResponse()->getBody(true))->messageInfo;
- return (object)array(
- "status" => false,
- "status_code" => $data->code,
- "message" => $data->message
- );
- }
- }
- public function guzzLoginOtp($token = "", $otp = "")
- {
- try
- {
- $promise = $this
- ->client
- ->requestAsync('POST', 'auth/otp', ['json' => ['token' => $token, 'otp' => $otp]]);
- $response = $promise->wait();
- $data = json_decode($response->getBody()
- ->getContents());
- //{"status":1,"messageInfo":{"code":"AUTH-013","title":"PIN salah, Kesempatan tinggal 3 kali lagi","message":"PIN salah, Kesempatan tinggal 3 kali lagi"}}
- $authorization = $response->getHeader('Authorization') [0];
- // var_dump($data);
- if ($response->getStatusCode() == 200 && $data->status == 0)
- {
- //sukses
- return (object)array(
- "status" => true,
- "status_code" => "OK",
- "data" => $data,
- "token" => $authorization
- );
- }
- else
- {
- //error
- return (object)array(
- "status" => false,
- "status_code" => "ERR-002",
- "message" => $data->message
- );
- }
- }
- catch(\Exception $e)
- {
- //do nothing
- $data = json_decode($e->getResponse()->getBody(true))->messageInfo;
- return (object)array(
- "status" => false,
- "status_code" => $data->code,
- "message" => $data->message
- );
- }
- }
- public function guzzProduct($trxType = "AP_BULK", $msisdn, $brand, $outletId, $token)
- {
- try
- {
- $promise = $this
- ->client
- ->requestAsync('GET', 'product?msisdn=' . $msisdn . '&brand=' . $brand . '&outletId=' . $outletId . '&trxType=' . $trxType, ['headers' => ['Authorization' => 'Bearer ' . $token]]);
- $response = $promise->wait();
- $data = json_decode($response->getBody()
- ->getContents());
- if ($response->getStatusCode() == 200 && $data->status == 0)
- {
- return (object)array(
- "status" => true,
- "status_code" => "OK",
- "data" => $data->data
- );
- }
- else
- {
- return (object)array(
- "status" => false,
- "status_code" => "ERR-" . $data->status,
- "message" => $data->message
- );
- }
- }
- catch(\Exception $e)
- {
- //do nothing
- $data = json_decode($e->getResponse()->getBody(true))->messageInfo;
- return (object)array(
- "status" => false,
- "status_code" => $data->code,
- "message" => $data->message
- );
- }
- }
- public function guzzItem($type = "brand", $msisdn, $token)
- {
- try
- {
- $promise = $this
- ->client
- ->requestAsync('GET', 'product/' . $type . '?msisdn=' . $msisdn, ['headers' => ['Authorization' => 'Bearer ' . $token]]);
- $response = $promise->wait();
- $data = json_decode($response->getBody()
- ->getContents());
- if ($response->getStatusCode() == 200 && $data->status == 0)
- {
- return (object)array(
- "status" => true,
- "status_code" => "OK",
- "data" => $data->data
- );
- }
- else
- {
- return (object)array(
- "status" => false,
- "status_code" => "ERR-" . $data->status,
- "message" => $data->message
- );
- }
- }
- catch(\Exception $e)
- {
- //do nothing
- $data = json_decode($e->getResponse()->getBody(true))->messageInfo;
- return (object)array(
- "status" => false,
- "status_code" => $data->code,
- "message" => $data->message
- );
- }
- }
- public function guzzProductHVC($trxType = "HVC", $msisdn, $class, $token)
- {
- try
- {
- $promise = $this
- ->client
- ->requestAsync('POST', 'product?msisdn=' . $msisdn . '&hvcClassification=' . strtoupper($class) . '&trxType=' . $trxType, ['headers' => ['Authorization' => $token]]);
- $response = $promise->wait();
- $data = json_decode($response->getBody()
- ->getContents());
- //{"status":1,"messageInfo":{"code":"AUTH-013","title":"PIN salah, Kesempatan tinggal 3 kali lagi","message":"PIN salah, Kesempatan tinggal 3 kali lagi"}}
- }
- catch(\Exception $e)
- {
- //do nothing
- $data = json_decode($e->getResponse()->getBody(true))->messageInfo;
- return (object)array(
- "status" => false,
- "status_code" => $data->code,
- "message" => $data->message
- );
- }
- }
- public function guzzProfile($code, $token)
- {
- try
- {
- $promise = $this
- ->client
- ->requestAsync('GET', 'user/profile?code=' . $code . '&_=' . time() , ['headers' => ['Authorization' => 'Bearer ' . $token, 'Connection' => 'keep-alive']]);
- $response = $promise->wait();
- $data = json_decode($response->getBody()
- ->getContents());
- if ($response->getStatusCode() == 200 && $data->status == 0)
- {
- return (object)array(
- "status" => true,
- "status_code" => "OK",
- "data" => $data->data
- );
- }
- else
- {
- return (object)array(
- "status" => false,
- "status_code" => $data
- ->messageInfo->code,
- "message" => $data
- ->messageInfo
- ->message
- );
- }
- }
- catch(\Exception $e)
- {
- //do nothing
- $data = json_decode($e->getResponse()->getBody(true))->messageInfo;
- return (object)array(
- "status" => false,
- "status_code" => $data->code,
- "message" => $data->message
- );
- }
- }
- public function guzzProductVoucher($token) {
- try
- {
- $promise = $this
- ->client
- ->requestAsync('GET', '/api/product/?trxType=VF', ['headers' => ['authorization' => 'Bearer ' . $token]]);
- $response = $promise->wait();
- $data = json_decode($response->getBody()
- ->getContents());
- if ($response->getStatusCode() == 200 && $data->status == 0)
- {
- return (object)array(
- "status" => true,
- "status_code" => "OK",
- "data" => $data->data
- );
- }
- else
- {
- return (object)array(
- "status" => false,
- "status_code" => "ERR-004",
- "message" => "Tidak dapat mengambil detail produk"
- );
- }
- }
- catch(\Exception $e)
- {
- //do nothing
- $data = json_decode($e->getResponse()->getBody(true))->messageInfo;
- return (object)array(
- "status" => false,
- "status_code" => $data->code,
- "message" => $data->message
- );
- }
- }
- public function guzzProductMkios($rsNumber = "", $pin = "", $outletId = "", $token = "") {
- try
- {
- $promise = $this
- ->client
- ->requestAsync('GET', '/api/product/mkios?rsNumber=' . $rsNumber . "&pin=" . $pin . "&outletId=" . $outletId, ['headers' => ['authorization' => 'Bearer ' . $token]]);
- $response = $promise->wait();
- $data = json_decode($response->getBody()
- ->getContents());
- if ($response->getStatusCode() == 200 && $data->status == 0)
- {
- return (object)array(
- "status" => true,
- "status_code" => "OK",
- "data" => $data->data
- );
- }
- else
- {
- return (object)array(
- "status" => false,
- "status_code" => "ERR-004",
- "message" => "Tidak dapat mengambil detail produk"
- );
- }
- }
- catch(\Exception $e)
- {
- //do nothing
- $data = json_decode($e->getResponse()->getBody(true))->messageInfo;
- return (object)array(
- "status" => false,
- "status_code" => $data->code,
- "message" => $data->message
- );
- }
- }
- public function guzzProductErin($msisdn = "", $productId = "", $rsNumber = "", $trxType = "", $token = "")
- {
- try
- {
- $promise = $this
- ->client
- ->requestAsync('GET', '/api/product/erin?msisdn=' . $msisdn . "&productId=" . $productId . "&rsNumber=" . $rsNumber . "&trxType=" . $trxType, ['headers' => ['authorization' => 'Bearer ' . $token]]);
- $response = $promise->wait();
- $data = json_decode($response->getBody()
- ->getContents());
- if ($response->getStatusCode() == 200 && $data->status == 0)
- {
- return (object)array(
- "status" => true,
- "status_code" => "OK",
- "data" => $data->data
- );
- }
- else
- {
- return (object)array(
- "status" => false,
- "status_code" => "ERR-004",
- "message" => "Tidak dapat mengambil detail produk"
- );
- }
- }
- catch(\Exception $e)
- {
- //do nothing
- $data = json_decode($e->getResponse()->getBody(true))->messageInfo;
- return (object)array(
- "status" => false,
- "status_code" => $data->code,
- "message" => $data->message
- );
- }
- }
- public function guzzAktivasiPaket($price = "", $pin = "", $msisdn = "", $packageId = "", $rsNumber = "", $userId = "", $outletId = "", $token = "")
- {
- $curl = curl_init();
- curl_setopt_array($curl, array(
- CURLOPT_URL => "https://digipos.telkomsel.com/api/package-activation",
- CURLOPT_RETURNTRANSFER => true,
- CURLOPT_ENCODING => "",
- CURLOPT_MAXREDIRS => 10,
- CURLOPT_TIMEOUT => 150,
- CURLOPT_CONNECTTIMEOUT => 100,
- CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
- CURLOPT_CUSTOMREQUEST => "POST",
- CURLOPT_POSTFIELDS => "------WebKitFormBoundary7MA4YWxkTrZu0gW\r\nContent-Disposition: form-data; name=\"price\"\r\n\r\n".trim($price)."\r\n------WebKitFormBoundary7MA4YWxkTrZu0gW\r\nContent-Disposition: form-data; name=\"pin\"\r\n\r\n".trim($pin)."\r\n------WebKitFormBoundary7MA4YWxkTrZu0gW\r\nContent-Disposition: form-data; name=\"msisdn\"\r\n\r\n".trim($msisdn)."\r\n------WebKitFormBoundary7MA4YWxkTrZu0gW\r\nContent-Disposition: form-data; name=\"packageId\"\r\n\r\n".trim($packageId)."\r\n------WebKitFormBoundary7MA4YWxkTrZu0gW\r\nContent-Disposition: form-data; name=\"rsNumber\"\r\n\r\n".trim($rsNumber)."\r\n------WebKitFormBoundary7MA4YWxkTrZu0gW\r\nContent-Disposition: form-data; name=\"userId\"\r\n\r\n".trim($userId)."\r\n------WebKitFormBoundary7MA4YWxkTrZu0gW\r\nContent-Disposition: form-data; name=\"outletId\"\r\n\r\n".trim($outletId)."\r\n------WebKitFormBoundary7MA4YWxkTrZu0gW--",
- CURLOPT_HTTPHEADER => array(
- "authorization: Bearer " . trim($token),
- "cache-control: no-cache",
- "content-type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW",
- "postman-token: 7587f3e8-5d66-38f7-3162-26220beef978"
- ),
- ));
- $response = curl_exec($curl);
- $err = curl_error($curl);
- $httpCode = curl_getinfo($curl, CURLINFO_HTTP_CODE);
- curl_close($curl);
- $data = json_decode($response);
- if($httpCode == 200 && $data->status == 0) {
- return (object)array("status" => true, "status_code" => "OK", "data" => $data);
- } else {
- return (object)array("status" => false, "status_code" => "ERR-" . array_key_exists("status", $data) ? $data->status : "ERR-002", "message" => array_key_exists("message", $data) ? $data->message : "Digipos not responding");
- }
- }
- public function guzzRechargePulsa($price = "", $pin = "", $msisdn = "", $packageId = "", $rsNumber = "", $userId = "", $outletId = "", $token = "")
- {
- $boundary = '----WebKitFormBoundary7MA4YWxkTrZu0gW';
- $multipart_form = [['name' => 'denomRecharge', 'contents' => $price], ['name' => 'pin', 'contents' => $pin, ], ['name' => 'msisdn', 'contents' => $msisdn, ], ['name' => 'productId', 'contents' => $packageId, ], ['name' => 'rsNumber', 'contents' => $rsNumber, ], ['name' => 'userId', 'contents' => $userId, ], ['name' => 'outletId', 'contents' => $outletId, ]];
- try
- {
- $promise = $this
- ->client
- ->requestAsync('POST', '/api/recharge', ['headers' => ['accept' => 'application/json, text/javascript, */*; q=0.01', 'authorization' => 'Bearer ' . $token, 'cache-control' => 'no-cache', 'content-type' => 'multipart/form-data; boundary=' . $boundary], 'body' => new GuzzleHttp\Psr7\MultipartStream($multipart_form, $boundary) , ]);
- $response = $promise->wait();
- $data = json_decode($response->getBody()
- ->getContents());
- if ($response->getStatusCode() == 200)
- {
- if (!is_null($data) && $data->status == 0)
- {
- return (object)array(
- "status" => true,
- "status_code" => "OK",
- "data" => $data
- );
- }
- else
- {
- return (object)array(
- "status" => false,
- "status_code" => "ERR-" . array_key_exists("status", $data) ? $data->status : "ERR-002",
- "message" => array_key_exists("message", $data) ? $data->message : "Digipos not responding"
- );
- }
- }
- else
- {
- return (object)array(
- "status" => false,
- "status_code" => array_key_exists("messageInfo", $data) ? $data
- ->messageInfo->code : "ERR-002",
- "message" => array_key_exists("messageInfo", $data) ? $data
- ->messageInfo->message : "Digipos not responding"
- );
- }
- }
- catch(\Exception $e)
- {
- //do nothing
- $data = json_decode($e->getResponse()->getBody(true))->messageInfo;
- return (object)array(
- "status" => false,
- "status_code" => $data->code,
- "message" => $data->message
- );
- }
- }
- public function guzzReport($startDate = "", $endDate = "", $userId = "", $rsNumber = "", $token = "")
- {
- try
- {
- $promise = $this
- ->client
- ->requestAsync('GET', '/api/package-activation/report?startDate=' . $startDate . "&endDate=" . $endDate . "&userId=" . $userId . "&rsNumber=" . $rsNumber, ['headers' => ['authorization' => 'Bearer ' . $token]]);
- $response = $promise->wait();
- $data = json_decode($response->getBody()
- ->getContents());
- if ($response->getStatusCode() == 200 && $data->status == 0)
- {
- return (object)array(
- "status" => true,
- "status_code" => "OK",
- "data" => $data->data
- );
- }
- else
- {
- return (object)array(
- "status" => false,
- "status_code" => "ERR-" . $data
- ->messageInfo->code,
- "message" => $data
- ->messageInfo
- ->message
- );
- }
- }
- catch(\Exception $e)
- {
- //do nothing
- $data = json_decode($e->getResponse()->getBody(true))->messageInfo;
- return (object)array(
- "status" => false,
- "status_code" => $data->code,
- "message" => $data->message
- );
- }
- }
- public function guzzPrepaidRegistration()
- {
- try
- {
- $promise = $this
- ->client
- ->requestAsync('GET', '/outapp/prepaidregistration', ['headers' => ['authorization' => 'Bearer ' . $token, 'cache-control' => 'no-cache']]);
- $response = $promise->wait();
- }
- catch(\Exception $e)
- {
- //do nothing
- $data = json_decode($e->getResponse()->getBody(true))->messageInfo;
- return (object)array(
- "status" => false,
- "status_code" => $data->code,
- "message" => $data->message
- );
- }
- }
- private function guzzVoucherBeli($pin = "", $productId = "", $tujuan = "", $token = "") {
- try
- {
- $promise = $this
- ->client
- ->requestAsync('POST', '/api/voucher-fisik', ['debug' => true, 'headers' => ['authorization' => 'Bearer ' . trim($token)], 'json' => [
- 'pin' => $pin,
- 'productId' => $productId,
- 'serialNumber' => $tujuan
- ]]);
- $response = $promise->wait();
- $data = json_decode($response->getBody()
- ->getContents());
- var_dump($data);
- if ($response->getStatusCode() == 200 && $data->status == 0)
- {
- return (object)array(
- "status" => true,
- "status_code" => "OK",
- "data" => $data->data
- );
- }
- else
- {
- return (object)array(
- "status" => false,
- "status_code" => $data
- ->messageInfo->code,
- "message" => $data
- ->messageInfo
- ->message
- );
- }
- }
- catch(\Exception $e)
- {
- //do nothing
- echo $e->getResponse()->getBody(true);
- $data = json_decode($e->getResponse()->getBody(true))->messageInfo;
- return (object)array(
- "status" => false,
- "status_code" => $data->code,
- "message" => $data->message
- );
- }
- }
- private function guzzVoucherReport($startDate, $endDate, $userId, $rsNumber, $token) {
- try
- {
- $promise = $this
- ->client
- ->requestAsync('GET', '/api/voucher-fisik/report?startDate=' . $startDate . '&endDate=' . $endDate . '&userId=' . $userId . '&rsNumber=' . $rsNumber, ['headers' => ['authorization' => 'Bearer ' . $token]]);
- $response = $promise->wait();
- $data = json_decode($response->getBody()
- ->getContents());
- if ($response->getStatusCode() == 200 && $data->status == 0)
- {
- return (object)array(
- "status" => true,
- "status_code" => "OK",
- "data" => $data->data
- );
- }
- else
- {
- return (object)array(
- "status" => false,
- "status_code" => $data
- ->messageInfo->code,
- "message" => $data
- ->messageInfo
- ->message
- );
- }
- }
- catch(\Exception $e)
- {
- //do nothing
- $data = json_decode($e->getResponse()->getBody(true))->messageInfo;
- return (object)array(
- "status" => false,
- "status_code" => $data->code,
- "message" => $data->message
- );
- }
- }
- //api/voucher-fisik/erin?productId=
- private function guzzVoucherErin($productId = "", $token = "") {
- try
- {
- $promise = $this
- ->client
- ->requestAsync('GET', '/api/voucher-fisik/erin?productId=' . $productId, ['headers' => ['authorization' => 'Bearer ' . $token]]);
- $response = $promise->wait();
- $data = json_decode($response->getBody()
- ->getContents());
- if ($response->getStatusCode() == 200 && $data->status == 0)
- {
- return (object)array(
- "status" => true,
- "status_code" => "OK",
- "data" => $data->data
- );
- }
- else
- {
- return (object)array(
- "status" => false,
- "status_code" => $data
- ->messageInfo->code,
- "message" => $data
- ->messageInfo
- ->message
- );
- }
- }
- catch(\Exception $e)
- {
- //do nothing
- $data = json_decode($e->getResponse()->getBody(true))->messageInfo;
- return (object)array(
- "status" => false,
- "status_code" => $data->code,
- "message" => $data->message
- );
- }
- }
- //voucher-fisik/validate?serialNumber=900008179616
- private function guzzValidateVoucher($voucher = "", $token = "") {
- try
- {
- $promise = $this
- ->client
- ->requestAsync('GET', '/api/voucher-fisik/validate?serialNumber=' . $voucher, ['headers' => ['authorization' => 'Bearer ' . $token]]);
- $response = $promise->wait();
- $data = json_decode($response->getBody()
- ->getContents());
- if ($response->getStatusCode() == 200 && $data->status == 0)
- {
- return (object)array(
- "status" => true,
- "status_code" => "OK",
- "data" => $data->data
- );
- }
- else
- {
- return (object)array(
- "status" => false,
- "status_code" => $data
- ->messageInfo->code,
- "message" => $data
- ->messageInfo
- ->message
- );
- }
- }
- catch(\Exception $e)
- {
- //do nothing
- $data = json_decode($e->getResponse()->getBody(true))->messageInfo;
- return (object)array(
- "status" => false,
- "status_code" => $data->code,
- "message" => $data->message
- );
- }
- }
- private function guzzRechargeReport($startDate = "", $endDate = "", $userId = "", $rsNumber = "", $token = "")
- {
- try
- {
- $promise = $this
- ->client
- ->requestAsync('GET', '/api/recharge/report?startDate=' . $startDate . '&endDate=' . $endDate . '&userId=' . $userId . '&rsNumber=' . $rsNumber, ['headers' => ['authorization' => 'Bearer ' . $token]]);
- $response = $promise->wait();
- $data = json_decode($response->getBody()
- ->getContents());
- if ($response->getStatusCode() == 200 && $data->status == 0)
- {
- return (object)array(
- "status" => true,
- "status_code" => "OK",
- "data" => $data->data
- );
- }
- else
- {
- return (object)array(
- "status" => false,
- "status_code" => $data
- ->messageInfo->code,
- "message" => $data
- ->messageInfo
- ->message
- );
- }
- }
- catch(\Exception $e)
- {
- //do nothing
- $data = json_decode($e->getResponse()->getBody(true))->messageInfo;
- return (object)array(
- "status" => false,
- "status_code" => $data->code,
- "message" => $data->message
- );
- }
- }
- /** DIGIMON UTILITIES FUNCTION **/
- public function searchReport($report = array() , $tujuan = "", $idProduk = "")
- {
- foreach ($report as $key => $value)
- {
- if ($value->msisdn == $tujuan && $value
- ->product->productId == $idProduk)
- {
- return $value;
- break;
- }
- }
- return null;
- }
- public function searchRechargeReport($report = array() , $tujuan = "", $denom = "")
- {
- foreach ($report as $key => $value)
- {
- if ($value->msisdn == $tujuan && $value->denomRecharge == $denom)
- {
- return $value;
- break;
- }
- }
- return null;
- }
- private function parseTipeProduk($tipe = "")
- {
- if ($tipe == "digital")
- {
- $trxType = "DIGITAL";
- }
- elseif ($tipe == "bulk")
- {
- $trxType = "AP_BULK";
- }
- elseif ($tipe == "voice")
- {
- $trxType = "AP_VOICE";
- }
- elseif ($tipe == "sms")
- {
- $trxType = "AP_SMS";
- }
- elseif ($tipe == "fix")
- {
- $trxType = "AP_FIX";
- }
- elseif ($tipe = "voucher")
- {
- $trxType = "VF";
- }
- return $trxType;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement