Advertisement
fahmihilmansyah

untuk mylibs

Dec 5th, 2020
1,839
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 9.99 KB | None | 0 0
  1. <?php
  2. /**
  3.  * Created by PhpStorm.
  4.  * Project : mymumuapps
  5.  * User: fahmihilmansyah
  6.  * Date: 30/10/20
  7.  * Email : fahmi.hilmansyah@gmail.com
  8.  * Telp : 0817170820
  9.  * Time: 05.58
  10.  * Dilarang Keras Mengubah atau Mendistribusikan ulang code ini tanpa sepengetahuan.
  11.  */
  12.   namespace app\Fhhlib;
  13.   use app\models\LogPpob;
  14.   use app\models\TransaksiIpg;
  15.   use yii\helpers\Url;
  16.  
  17.   class Mylibs{
  18.  
  19.       protected static $urlpa= 'http://core.mumuapps.id/';
  20. //      protected static $mkey= 'SECRETKEY12839';
  21.       protected static $mkey= 'SECRETKEY123332';
  22.       protected static $appkey= 'DDTEKNOMUMUPAYMENT1234';
  23.       protected static $appkeywalet= 'APPKEYDDTEKNOMUMU';
  24.       public static function uuidv4()
  25.       {
  26.           return time() . "-" . sprintf('%04x%04x-%04x-%04x-%04x-%04x%04x%04x',
  27.  
  28.                   // 32 bits for "time_low"
  29.                   mt_rand(0, 0xffff), mt_rand(0, 0xffff),
  30.  
  31.                   // 16 bits for "time_mid"
  32.                   mt_rand(0, 0xffff),
  33.  
  34.                   // 16 bits for "time_hi_and_version",
  35.                   // four most significant bits holds version number 4
  36.                   mt_rand(0, 0x0fff) | 0x4000,
  37.  
  38.                   // 16 bits, 8 bits for "clk_seq_hi_res",
  39.                   // 8 bits for "clk_seq_low",
  40.                   // two most significant bits holds zero and one for variant DCE1.1
  41.                   mt_rand(0, 0x3fff) | 0x8000,
  42.  
  43.                   // 48 bits for "node"
  44.                   mt_rand(0, 0xffff), mt_rand(0, 0xffff), mt_rand(0, 0xffff)
  45.               );
  46.       }
  47.       static function _signaturecheck($data=[]){
  48.           $result_code = $data['result_code']??'';
  49.           $result_desc = $data['result_desc']??'';
  50.           $invoice = $data['invoice']??'';
  51.           $amount = $data['amount']??'';
  52.           $pay_date = $data['pay_date']??'';
  53.           $ref_no = $data['ref_no']??'';
  54.           $bill = $data['bill']??'';
  55.           $sof_id = $data['sof_id']??'';
  56.           $signature = hash_hmac('sha256', $result_code . '|' . $result_desc . '|' . $invoice . '|' . $amount . '|' . $pay_date . '|' . $ref_no . '|' . $bill . '|' . $sof_id, self::$mkey);
  57.           return $signature;
  58.       }
  59.       static function _curl_exec_ipg($arrParam)
  60.       {
  61. //          $cquery = new Fhhlib();
  62. //          $cariipg = $cquery->custom_query('nb_partner_ipg', ['where' => ['id' => $cquery->db->escape('MUPAYS')]])->result();
  63.           $urlfinpay = self::$urlpa.'trx/request';
  64.           $signature = hash_hmac('sha256', $arrParam['invoice'] . '|' . $arrParam['amount'] . '|' . $arrParam['cust_email'] . '|' . $arrParam['cust_msisdn']  . '|' .$arrParam['sof_id'] , self::$mkey);
  65.           $arrParam['signature'] = $signature;
  66.           $postfields = http_build_query($arrParam);
  67.           $ch = curl_init();
  68.           curl_setopt($ch, CURLOPT_POST, 1);
  69.           curl_setopt($ch, CURLOPT_URL, $urlfinpay);
  70.           curl_setopt($ch, CURLOPT_POSTFIELDS, $postfields);
  71.           curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  72.           curl_setopt($ch, CURLOPT_HTTPHEADER, array(
  73.               'Pauthorization: '.self::$appkey
  74.           ));
  75.           $response = curl_exec($ch);
  76. //          print_r($response);exit;
  77.           $err = curl_error($ch);
  78.           curl_close($ch);
  79.           if ($err) {
  80.               echo "cURL Error #:" . $err;
  81.           } else {
  82.               $insrt = new  TransaksiIpg();
  83.               $insrt->id = self::uuidv4();
  84.               $insrt->request_json = json_encode($arrParam);
  85.               $insrt->response_json = $response;
  86.               $insrt->target_table = 'transaksi';
  87.               $insrt->status = 'WAITING';
  88.               $insrt->trxid = $arrParam['invoice'];
  89.               $insrt->created_ad = date('Y-m-d H:i:s');
  90.               $insrt->save();
  91.               $response = ($response);
  92. //            if($response['status_code'] == '00'){
  93. //                return $response['landing_page'];
  94. //            }else{
  95.               return $response;
  96. //            }
  97.               print_r($response);
  98.           }
  99.       }
  100.       public static function SendMail($data = array())
  101.       {
  102.           try {
  103.               $lsdata['config']['type'] = 'smtp';
  104.               $lsdata['config']['host'] = 'smtp.gmail.com';
  105.               $lsdata['config']['username'] = 'no-reply@ddtekno.com';
  106.               $lsdata['config']['password'] = 'ddtekno92528';
  107.               $lsdata['config']['port'] = '587';
  108.               $lsdata['config']['encryption'] = 'tls';
  109.               $lsdata['fromName'] = $data["senderName"];
  110.               $lsdata['to'] = $data["emailTo"];
  111.               $lsdata['subject'] = $data["subject"];
  112.               $lsdata['html'] = $data["konten"];
  113.               Mylibs::sendemailbyurl($lsdata);
  114.           }catch(\Exception $e){
  115.               print_r($e->getMessage());exit;
  116.           }
  117.       }
  118.       static function sendemailbyurl($postData){
  119.           try {
  120.  
  121.               $ch = curl_init();
  122.  
  123.               $curl = curl_init();
  124.  
  125.               curl_setopt_array($curl, array(
  126.                   CURLOPT_URL => "http://194.31.53.26/kirimemail/public/kirim2",
  127.                   CURLOPT_RETURNTRANSFER => true,
  128.                   CURLOPT_FOLLOWLOCATION => true,
  129.                   CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  130.                   CURLOPT_CUSTOMREQUEST => "POST",
  131.                   CURLOPT_POSTFIELDS =>json_encode($postData),
  132.                   CURLOPT_HTTPHEADER => array(
  133.                       "Content-Type: application/json"
  134.                   ),
  135.               ));
  136.  
  137.               $response = curl_exec($curl);
  138.  
  139.               curl_close($curl);
  140. //            echo $response;
  141.               return $response;
  142.           }catch (\Exception $e){
  143.               print_r($e->getMessage());
  144.           }
  145.  
  146.       }
  147.       public static function existsImage($path, $img)
  148.       {
  149.           $dPath = \Yii::getAlias('@webroot/uploads') ;;
  150.           $rpath = $dPath . $path . $img;
  151.           $url_image = Url::to(['/template/img/logomumu-dark.png'],true);
  152.           if(!empty($img))
  153.           {
  154.               if(file_exists($rpath))
  155.               {
  156.                   $url_image = Url::to(['/uploads/'.$path.'/'.$img]);
  157.               }
  158.           }
  159.  
  160.           return $url_image;
  161.       }
  162.       static function _koneksi_ppob($data = [],$type='INQ',$no_transaksi='')
  163.       {
  164.           try {
  165.  
  166.  
  167.               $curl = curl_init();
  168.               curl_setopt_array($curl, array(
  169.                   CURLOPT_URL => "http://core.mumuapps.id/ppob/b2b/transaksi",
  170.                   CURLOPT_RETURNTRANSFER => true,
  171.                   CURLOPT_ENCODING => "",
  172.                   CURLOPT_MAXREDIRS => 10,
  173.                   CURLOPT_TIMEOUT => 0,
  174.                   CURLOPT_FOLLOWLOCATION => true,
  175.                   CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  176.                   CURLOPT_CUSTOMREQUEST => "POST",
  177.                   CURLOPT_POSTFIELDS => $data,
  178.               ));
  179.               $response = curl_exec($curl);
  180.               curl_close($curl);
  181.               $logppob = new LogPpob();
  182.               $logppob->id = self::uuidv4();
  183.               $logppob->no_transaksi = $no_transaksi;
  184.               $logppob->req_json = json_encode($data);
  185.               $logppob->res_json = $response;
  186.               $logppob->created_ad = date('Y-m-d H:i:s');
  187.               $logppob->type = $type;
  188.               $logppob->save();
  189.               return $response;
  190.           }catch (\Exception $e){
  191.               print_r($e->getMessage());
  192.               exit;
  193.           }
  194.  
  195.       }
  196.       static function _koneksi_ppob2($data=[]){
  197.               $curl = curl_init();
  198.               curl_setopt_array($curl, array(
  199.                   CURLOPT_URL => "http://core.mumuapps.id/ppob/b2b/transaksi",
  200.                   CURLOPT_RETURNTRANSFER => true,
  201.                   CURLOPT_ENCODING => "",
  202.                   CURLOPT_MAXREDIRS => 10,
  203.                   CURLOPT_TIMEOUT => 0,
  204.                   CURLOPT_FOLLOWLOCATION => true,
  205.                   CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  206.                   CURLOPT_CUSTOMREQUEST => "POST",
  207.                   CURLOPT_POSTFIELDS => $data,
  208.               ));
  209.               $response = curl_exec($curl);
  210.               curl_close($curl);
  211.               return $response;
  212.  
  213.       }
  214.  
  215.       static function _curl_exexc_ppob($slugurl = '', $postdata = '', $METHOD = 'POST', $HEADER =[])
  216.       {
  217. //          $HEADER = array('TOKEN-KEY: '.self::$appkey, 'APP-KEY: '.self::$appkeywalet);
  218. //        $postdata = http_build_query($data);
  219.           // create curl resource
  220.           $ch = curl_init();
  221.  
  222.           // set url
  223.           curl_setopt($ch, CURLOPT_URL, self::$urlpa.$slugurl);
  224.           //return the transfer as a string
  225.           curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $METHOD);
  226.           curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  227.           curl_setopt($ch, CURLOPT_POSTFIELDS, $postdata);
  228.           curl_setopt($ch, CURLOPT_HTTPHEADER, $HEADER);
  229.  
  230.           // $output contains the output string
  231.           $output = curl_exec($ch);
  232.           echo "hasil";
  233.           echo ($output);
  234.           // close curl resource to free up system resources
  235.           curl_close($ch);
  236.           return $output;
  237.       }
  238.       static function _curl_exexc_walet($slugurl = '', $postdata = '', $METHOD = 'POST', $HEADER =[])
  239.       {
  240.           $HEADER = array('TOKEN-KEY: '.self::$appkey, 'APP-KEY: '.self::$appkeywalet);
  241. //        $postdata = http_build_query($data);
  242.           // create curl resource
  243.           $ch = curl_init();
  244.  
  245.           // set url
  246.           curl_setopt($ch, CURLOPT_URL, self::$urlpa.$slugurl);
  247.           //return the transfer as a string
  248.           curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $METHOD);
  249.           curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  250.           curl_setopt($ch, CURLOPT_POSTFIELDS, $postdata);
  251.           curl_setopt($ch, CURLOPT_HTTPHEADER, $HEADER);
  252.  
  253.           // $output contains the output string
  254.           $output = curl_exec($ch);
  255.           // close curl resource to free up system resources
  256.           curl_close($ch);
  257.           return $output;
  258.       }
  259.   }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement