Advertisement
Guest User

Untitled

a guest
Dec 13th, 2018
208
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 46.26 KB | None | 0 0
  1. <?php
  2. /**
  3.  * Prima Recharge Script
  4.  * Recharge Prima from
  5.  * given postpaid number
  6.  *
  7.  * script migrated to smsapp.mtel.bg
  8.  * cluster on date 19.01.2012 year
  9.  *
  10.  * Changes:
  11.  *  Added CRM Auto Notification log 19.01.2012 (i.stoyanov@mobiltel.bg)
  12.  *  Added recognition for 6 and 06 lv. on 26.01.2012 (i.stoyanov@mobiltel.bg)
  13.  *  Added Global Blacklist functionality on 30.01.2012
  14.  *  Changed M13 reply sms text via e-mail request from Zhulieta Blazheva (i.stoyanov@mobiltel.bg)
  15.  *  Due Shafran project sms texts change done on 30.08.2012
  16.  */
  17.  
  18. ini_set ( "max_execution_time", 100 ); # sets max_execution_time to bigger than default (30 sec) value.
  19. ini_set('soap.wsdl_cache_enabled', '0');
  20. define ( MAX_SMS_LEN, 160 ); //number of chars per SMS
  21. define ( INFO, "Za poveche informacia se obadete na 1010" );
  22. define ( M1, 'Zdraveyte, izpratili ste SMS s nekorektno sadarzhanie. Izpratete tekst "08XXXXXXXX,YY", kato 08XXXXXXXX e nomerat na karta za Predplatena usluga, a YY - suma za zarezhdane: 6, 10 ili 15' );
  23. define ( M2, "Zdraveyte, dostignahte limita za zarezhdane na karta za Predplatena usluga chrez SMS: do 1 zarezhdane na chas i do 2 na 24 chasa. Molya, opitayte otnovo po-kasno. A1" );
  24. define ( M3, "Zdraveyte, vazmozhnostta za zarezhdane na karta za Predplatena usluga chrez SMS se predlaga samo za klienti s dogovor. Za poveche informatsia: *88. A1" );
  25. define ( M4, "Zdraveyte, za da zaredite karta za Predplatena usluga chrez SMS, e neobhodimo da ste klient na A1 poveche ot 3 mesetsa. Molya, opitayte otnovo sled tozi srok. A1" );
  26. define ( M5, "Zdraveyte, dostignahte kreditnia limit za Vashia nomer i nyama vazmozhnost da zaredite karta za Predplatena usluga s posochenata suma. Za informatsia i po-visok limit: *88. A1" );
  27. define ( M6, "Zdraveyte, nomerat, koyto pozhelahte da zaredite, ne e karta za Predplatena usluga. Molya, proverete nomera i opitayte otnovo. A1" );
  28. define ( M7, "Zdraveyte, Vie zaredihte karta za Predplatena usluga nomer " );
  29. define ( M71, " s " );
  30. define ( M72, " lv. Tazi suma shte se otrazi v sledvashtata Vi mesechna smetka. A1" );
  31. define ( M8, "Your Prepaid service Card Has Just Been Recharged With YY BGN, VAT Inclusive, From Customer With Mobile Number " );
  32. define ( M9, "Zdraveyte, v momenta uslugata e nedostapna. Molya da ni izvinite! Mozhe da zaredite karta za Predplatena usluga, kato zakupite hartien vaucher. A1" );
  33. define ( M10, "Zdraveyte, Vashiyat nomer nyama vazmozhnost da zarezhda karta za Predplatena usluga chrez SMS. Za poveche informatsia: *88. A1" );
  34. define ( M11, "Zdraveyte, v momenta uslugata e nedostapna. Molya da ni izvinite! Mozhe da zaredite karta za Predplatena usluga, kato zakupite hartien vaucher. A1" );
  35. define ( M12, "Zdraveyte, Vie se otkazahte ot informatsionnite saobshtenia za niska suma po smetkata na nomera na karta za Predplatena usluga, koyto zarezhdate. Za da gi poluchavate otnovo: *88. A1" );
  36. define ( M13, 'Zdraveyte, izpratili ste SMS s nekorektno sadarzhanie. Izpratete tekst "08XXXXXXXX,YY", kato 08XXXXXXXX e nomerat na karta za Predplatena usluga, a YY - suma za zarezhdane: 6, 10 ili 15' );
  37. define ( M14, "Prez A1 Menu-to na telefona si mozhete da prezarezhdate karta za Predplatena usluga s 6, 10 ili 15 lv. Opitayte otnovo" );
  38.  
  39.  
  40. # before Shafran
  41. //define ( INFO, "Za poveche informacia se obadete na 1010" );
  42. //define ( M1, "Greshen format. Molya izpolzvayte sledniyat format: 088XXXXXXX,YY kadeto YY e stoynostta na sumata za zarezhdane - 6,10 ili 15. Blagodarim vi! Ekipat na Mtel." );
  43. //define ( M2, "Uvazhaemi klienti,Vie dostignahte limita si za zarezhdane - do 1 zarezhdane na chas, do 2 zarezhdania dnevno.Molya izchakayte i opitayte otnovo.Ekipat na Mtel." );
  44. //define ( M3, "Uvazhemi klienti, uslugata Zarezhdane na Prima chrez SMS mozhe da se izpolzva samo ot klienti na M-Tel s mesechen abonamenten dogovor. Ekipat na Mtel." );
  45. //define ( M4, "Zdraveyte,za da zarezhdate Prima chrez SMS, e neobhodimo da ste klient na M-Tel poveche ot 3 mesetsa.Molya opitayte otnovo,kogato tozi srok bade izpalnen.Mtel." );
  46. //define ( M5, "Uvazhaemi klienti, Vie dostignahte kreditnia si limit I zayavkata ne mozhe da bade izpalnena. Molya, uvelichete limita si na *88 ili vnesete depozit. Mtel." );
  47. //define ( M6, "Uvazhaemi klienti, nomerat, koyto ste posochili za zarezhdane, ne e klient na Prima. Molya opitayte otnovo. Ekipat na Mtel." );
  48. //define ( M7, "Uvazhaemi klienti, Vie uspeshno zaredihte Prima nomer " );
  49. //define ( M71, " s " );
  50. //define ( M72, " lv. s DDS. Tazi suma shte se otrazi v sledvashtata vi mesechna smetka.Ekipat na Mtel." );
  51. //define ( M8, "Your Prima Card Has Just Been Recharged With YY BGN, VAT Inclusive, From Customer With Mobile Number " );
  52. //define ( M9, "Uvazhaemi klienti, v momenta uslugata e nedostapna. Molya, opitayte po-kasno. Blagodarim Vi za razbiraneto. Ekipat na Mtel." );
  53. //define ( M10, "Uvazhaemi klienti, Vashiyat nomer ima zabrana za izpolzvane na uslugata Zarezhdane na Prima s SMS. Za poveche informatsia pozvanete na *88. Ekipat na Mtel." );
  54. //define ( M11, "Uslugata e vremenno nedostapna,molya opitayte otnovo sled 72 chasa.Mozhete da zaredite Prima kartata vednaga s hartien voucher. Blagodarim za razbiraneto!Mtel." );
  55. //define ( M12, "Zdraveyte, Vie uspeshno se otkazahte ot uslugata, koyato Vi informira za niska nalichnost po smetkata na nomera, koyto zarezhdate. Ekipat na Mtel" );
  56. //define ( M13, "Greshen format. Molya izpolzvayte slednia format: 088XXXXXXX,YY kadeto YY e stoynostta na sumata za zarezhdane - 6, 10 ili 15. Ekipat na Mtel" );
  57. //define ( M14, "Prez Mtel Menu-to na telefona si mozhete da prezarezhdate Prima s 6, 10 ili 15 lv. Opitayte otnovo" );
  58.  
  59.  
  60. # Get Subscriber type service WSDL
  61. define ('SUBSRIBER_TYPE_SERVICE_USER', 'subscrprd');
  62. define ('SUBSRIBER_TYPE_SERVICE_PASS', 'sub_prd');
  63. define ('SUBSRIBER_TYPE_SERVICE_WSDL','http://b2b.mtel.bg:8181/com_mtel_subscriber/Processes/Services/SubscriberService/Interface/SubscriberService.serviceagent?wsdl');
  64.  
  65.  
  66. define ( 'SUBSCRIBER_MESSAGING_SERVICE_UNIQUE_ID', 'dma_1616' . date ( "y" ) );
  67.  
  68. # prod service config  
  69. define ('SUBSCRIBER_MESSAGING_WSDL', 'https://soa.mtel.bg:9090/bs/SubscriberMessagingBS?wsdl' );
  70. define ('SUBSCRIBER_MESSAGING_LOCATION', 'https://soa.mtel.bg:9090/bs/SubscriberMessagingBS');
  71. define ('SUBSCRIBER_MESSAGING_LOGIN', 'soa');
  72. define ('SUBSCRIBER_MESSAGING_PASSWORD', 'mt3ls0@');
  73.  
  74. #test service config
  75. //define ( 'SUBSCRIBER_MESSAGING_WSDL', 'https://soatest.mtel.bg:9090/bs/SubscriberMessagingBS?wsdl' );
  76. //define ( 'SUBSCRIBER_MESSAGING_LOCATION', 'https://soatest.mtel.bg:9090/bs/SubscriberMessagingBS' );
  77. //define ( 'SUBSCRIBER_MESSAGING_LOGIN', 'mtel' );
  78. //define ( 'SUBSCRIBER_MESSAGING_PASSWORD', 'password' );
  79.  
  80.  
  81. # configuration for pico-push page
  82. define ( 'PICO_PUSH_LOGIN','pbelev');
  83. define ( 'PICO_PUSH_USER', 'paFkaTa');
  84. define ( 'PICO_PUSH_WSDL', 'http://wsdl.mtel.bg/pico-push/?wsdl' );
  85. define ( 'PICO_PUSH_PAGE', 'MTEL_PRIMA_RECHARGE_LOCAL');
  86.  
  87.  
  88. # Web Service for Global Blacklist
  89. define ('GBL_SERVICE_USER', 'web1616' );
  90. define ('GBL_SERVICE_PASS', 'bgfseEW#');
  91. define ('GBL_SERVICE_WSDL', 'http://sms.mtel.bg/gbl/1.0/?wsdl');
  92. define ('GBL_SERVICE_CHANNEL', 'sms');
  93. define ('GBL_SERVICE_CATEGORY', 'notification');
  94.  
  95.  
  96. require ("/home/sms/inc/PrimaRecharge/subscriberinformation.php");
  97. require ("/home/sms/inc/sql_wrap.php");
  98. require ("/home/sms/inc/PrimaRecharge/bam.lib.php");
  99.  
  100.  
  101. //Settings for SMSPrimaRecharge
  102. $SMSPrimaRecharge_db ["db"] = "SMSPrimaRecharge";
  103. $SMSPrimaRecharge_db ["host"] = "10.250.246.61";
  104. $SMSPrimaRecharge_db ["user"] = "prima_rech_user";
  105. $SMSPrimaRecharge_db ["pass"] = "sk343df64jsr6c";
  106.  
  107. //Settings for "PrepaidMMSBilling"
  108. $PrepaidMMSBilling_db ["db"] = "PrepaidMMSBilling";
  109. $PrepaidMMSBilling_db ["host"] = "213.226.6.50"; # localhost
  110. $PrepaidMMSBilling_db ["user"] = "prima_rech_user";
  111. $PrepaidMMSBilling_db ["pass"] = "kjldncuisfhs89fsd";
  112.  
  113. //Settings for "cdrs"
  114. $cdrs_db ["db"] = "cdrs";
  115. $cdrs_db ["host"] = "10.250.246.61";
  116. $cdrs_db ["user"] = "prima_rech_user";
  117. $cdrs_db ["pass"] = "sk343df64jsr6c";
  118.  
  119.  
  120. $current_year = date ( "Y" );
  121.  
  122. $bank_api_codes [0] = 'OK';
  123. $bank_api_codes [13] = 'Not valid amount for recharge';
  124. $bank_api_codes [14] = 'Invalid Prepaid MSISDN';
  125. $bank_api_codes [42] = 'Not enough deposit (prepaid resalers)';
  126. $bank_api_codes [80] = 'Request cannot be completed currently';
  127. $bank_api_codes [94] = 'Duplicated transaction ID';
  128. $bank_api_codes [96] = 'General error';
  129.  
  130.  
  131. //------------------------------------------------------------------------------------------------
  132. function log_sent($gsmnum, $smstext, $sms_id = 0)
  133. {
  134.     global $SMSPrimaRecharge_db, $current_year;
  135.    
  136.     $my_db = new Db ( $SMSPrimaRecharge_db ["host"], $SMSPrimaRecharge_db ["user"], $SMSPrimaRecharge_db ["pass"] );
  137.     $sql = "INSERT INTO SendLog_" . $current_year . "(input_log_id,destination,gsmnum,tstamp,sms_text) VALUES($sms_id,'" . $_GET ["receiver"] . "','$gsmnum',NOW(),'$smstext')";
  138.     $res = & $my_db->execute ( $SMSPrimaRecharge_db ["db"], $sql );
  139.     $my_db->close ();
  140.     return true;
  141. } //end log_sent
  142.  
  143.  
  144. //------------------------------------------------------------------------------------------------
  145. function log_em_all($destination, $gsmnum, $input)
  146. {
  147.     global $SMSPrimaRecharge_db, $current_year;
  148.    
  149.     $my_db = new Db ( $SMSPrimaRecharge_db ["host"], $SMSPrimaRecharge_db ["user"], $SMSPrimaRecharge_db ["pass"] );
  150.     $sql = "INSERT INTO InputLog_" . $current_year . "(destination,gsmnum,input,tstamp,stk_menu) VALUES('$destination','$gsmnum','$input',NOW(), ('$input' REGEXP ',stk$'))";
  151.     $res = & $my_db->execute ( $SMSPrimaRecharge_db ["db"], $sql );
  152.     $ins_id = $my_db->insert_id ();
  153.     $my_db->close ();
  154.     return $ins_id;
  155. } //end log_em_all
  156.  
  157.  
  158. //------------------------------------------------------------------------------------------------
  159. function sendsms($smstext, $gsmnum, $sms_id = 0)
  160. {
  161.    
  162.     Header ( "X-Kannel-DLR-Mask: 3" );
  163.    
  164.     Header ( "X-Kannel-DLR-Url: http://smsapp.mtel.bg/dlr/1616.php?smsid=$sms_id&sender=%p&tstamp=%T&dlr_status=%d&receiver=%P&message_id=" . $sms_id );
  165.     Header ( "X-Kannel-SMSC: " . $_GET ["smscid"] );
  166.     print $smstext;
  167.     log_sent ( $gsmnum, $smstext, $sms_id );
  168.     # add sms to CRM Automatic Notifications
  169.    register_mt_to_crm ( $gsmnum, 1616, $smstext, $sms_id );
  170.  
  171. } //end sendsms
  172.  
  173.  
  174. //------------------------------------------------------------------------------------------------
  175. function check_parallel_transaction($gsmnum, $sms_id)
  176. {
  177.     global $SMSPrimaRecharge_db, $current_year;
  178.    
  179.     $sql = "SELECT count(i.id) As opened_trans FROM InputLog_" . $current_year . " i LEFT JOIN SendLog_" . $current_year . " s ON (i.id=s.input_log_id) WHERE i.gsmnum = $gsmnum AND i.id!=$sms_id AND (i.tstamp > now() - interval 5 minute) AND s.id IS NULL";
  180.     #print $sql."<br>";
  181.    $my_db = new Db ( $SMSPrimaRecharge_db ["host"], $SMSPrimaRecharge_db ["user"], $SMSPrimaRecharge_db ["pass"] );
  182.     $res = & $my_db->execute ( $SMSPrimaRecharge_db ["db"], $sql );
  183.     $my_db->close ();
  184.    
  185.     if ($res [0] ["opened_trans"] == 0)
  186.     { #niama zapochnali i nezavarsheni zarejdania za tozi MSISDN
  187.        return false;
  188.     } else
  189.     {
  190.         return true; #ima in SMS, no oshte niama out SMS - t.e. in SMS-a se processva vse oshte ot scripta za tozi MSISDN
  191.    }
  192. } //end check_parallel_transaction
  193.  
  194.  
  195. //------------------------------------------------------------------------------------------------
  196. function check_flood($gsmnum)
  197. {
  198.     global $SMSPrimaRecharge_db, $current_year;
  199.    
  200.     /*
  201.     # for tests
  202.     if ($gsmnum==359888618754 || $gsmnum==359886850873 || $gsmnum==359888500783 || $gsmnum==359888500949  || $gsmnum==359886224422 || $gsmnum==359888618772 || $gsmnum==359888618778 || $gsmnum==359888500814 ||
  203.     $gsmnum==359888700783 || $gsmnum==359885035951) return false;
  204.     */
  205.    
  206.     $hourly_tries = 1;
  207.     $daily_tries = 2;
  208.    
  209.     $sql = "SELECT count(id) As tries FROM PrimaRechargeHistory_" . $current_year . " WHERE mo_msisdn = $gsmnum AND (recharge_date > now() - interval 60 minute)";
  210.     #print $sql."<br>";
  211.    $my_db = new Db ( $SMSPrimaRecharge_db ["host"], $SMSPrimaRecharge_db ["user"], $SMSPrimaRecharge_db ["pass"] );
  212.     $res = & $my_db->execute ( $SMSPrimaRecharge_db ["db"], $sql );
  213.    
  214.     if ($my_db->errno ())
  215.     {
  216.         $my_db->close ();
  217.         return true;
  218.     }
  219.     if ($res [0] ["tries"] >= $hourly_tries)
  220.     {
  221.         $my_db->close ();
  222.         return true;
  223.     }
  224.    
  225.     $sql = "SELECT count(id) As tries FROM PrimaRechargeHistory_" . $current_year . " WHERE mo_msisdn = $gsmnum AND (recharge_date > now() - interval 1 day)";
  226.     #print $sql."<br>";
  227.    $res = & $my_db->execute ( $SMSPrimaRecharge_db ["db"], $sql );
  228.    
  229.     if ($my_db->errno ())
  230.     {
  231.         $my_db->close ();
  232.         return true;
  233.     }
  234.     if ($res [0] ["tries"] >= $daily_tries)
  235.     {
  236.         $my_db->close ();
  237.         return true;
  238.     }
  239.     $my_db->close ();
  240.     return false;
  241. } //end check_flood
  242.  
  243.  
  244. //------------------------------------------------------------------------------------------------
  245. function make_PrimaRechargeHistory($gsmnum, $prima, $sum, $sms_id, $postpaid_primary_id, $recharge_date)
  246. {
  247.     global $SMSPrimaRecharge_db, $current_year;
  248.    
  249.     $sql = "INSERT INTO PrimaRechargeHistory_" . $current_year . "(input_log_id, mo_msisdn, recharged_msisdn, recharge_sum, recharge_date, postpaid_primary_id) VALUES($sms_id, $gsmnum, $prima, $sum, '".$recharge_date."', $postpaid_primary_id)";
  250.     #print $sql."\n";
  251.    $my_db = new Db ( $SMSPrimaRecharge_db ["host"], $SMSPrimaRecharge_db ["user"], $SMSPrimaRecharge_db ["pass"] );
  252.     $my_db->execute ( $SMSPrimaRecharge_db ["db"], $sql );
  253.     $my_db->close ();
  254. } //end make_PrimaRechargeHistory
  255.  
  256.  
  257. //------------------------------------------------------------------------------------------------
  258. function make_cdr($gsmnum, $prima, $sum, $amount, $recharge_dte)
  259. {
  260.     global $cdrs_db;
  261.    
  262.     $sql = "INSERT INTO cdrs.cdr_" . date ( "Ym" ) . "(software_version, switch_type, call_transaction, subscriber_type, caller_msisdn, other_party_type, receiving_party, service_type, dte, duration, amount, gw_name, application_id, processed_dte) VALUES(DEFAULT, 'S', 'Y', '1', $gsmnum, ' ', '#$sum#$prima', '34', $recharge_dte, DEFAULT, $amount, 'MISC', 1, DEFAULT)";
  263.     #print $sql."\n";
  264.    $my_db = new Db ( $cdrs_db ["host"], $cdrs_db ["user"], $cdrs_db ["pass"] );
  265.     $my_db->execute ( $cdrs_db ["db"], $sql );
  266.     #print_r($my_db);
  267.    $rows = $my_db->rows ();
  268.     $my_db->close ();
  269.     return $rows;
  270. } //end make_cdr
  271.  
  272.  
  273. //------------------------------------------------------------------------------------------------
  274. function uni2iso($uniline)
  275. {
  276.     $tmp = chunk_split ( $uniline, 4, ";" );
  277.     $tmp = explode ( ";", $tmp );
  278.     for($i = 0; $i < count ( $tmp ); $i ++)
  279.     {
  280.         $cnt = $tmp [$i];
  281.         $cnt = base_convert ( $cnt, 16, 10 );
  282.         $uni = str_pad ( $cnt, 4, "0", STR_PAD_LEFT );
  283.         $str .= ($cnt > 174) ? chr ( $cnt - 1040 + 176 ) : chr ( $cnt );
  284.     }
  285.     return convert_cyr_string ( $str, "i", "w" ); //$str;//
  286. } //end uni2iso
  287.  
  288.  
  289. //------------------------------------------------------------------------------------------------
  290. function str_to_lower($src)
  291. {
  292.     $dst = "";
  293.     $num = strlen ( $src );
  294.     for($i = 0; $i < $num; $i ++)
  295.     {
  296.         $char = $src [$i];
  297.         $ord = ord ( $char );
  298.         if ($ord >= 65 && $ord <= 90)
  299.         {
  300.             $ord = $ord + 32;
  301.             $dst .= chr ( $ord );
  302.         } elseif ($ord >= 192 && $ord <= 223)
  303.         {
  304.             $ord = $ord + 32;
  305.             $dst .= chr ( $ord );
  306.         } elseif (($ord >= 97 && $ord <= 122) || ($ord >= 224 && $ord <= 255) || ($ord >= 48 && $ord <= 57))
  307.         {
  308.             $dst .= $char;
  309.         } else
  310.         {
  311.             break; //chars not in a-zA-Z�-��-� are skipped - break after first word
  312.         }
  313.     }
  314.     return $dst;
  315. } //end str_to_lower
  316.  
  317.  
  318. //------------------------------------------------------------------------------------------------
  319. function utf8win1251($s)
  320. {
  321.     $out = "";
  322.     $c1 = "";
  323.     $byte2 = false;
  324.     for($c = 0; $c < strlen ( $s ); $c ++)
  325.     {
  326.         $i = ord ( $s [$c] );
  327.         if ($i <= 127)
  328.         {
  329.             $out .= $s [$c];
  330.         }
  331.         if ($byte2)
  332.         {
  333.             $new_c2 = ($c1 & 3) * 64 + ($i & 63);
  334.             $new_c1 = ($c1 >> 2) & 5;
  335.             $new_i = $new_c1 * 256 + $new_c2;
  336.             if ($new_i == 1025)
  337.                 $out_i = 168;
  338.             else if ($new_i == 1105)
  339.                 $out_i = 184;
  340.             else
  341.                 $out_i = $new_i - 848;
  342.             $out .= chr ( $out_i );
  343.             $byte2 = false;
  344.         }
  345.         if (($i >> 5) == 6)
  346.         {
  347.             $c1 = $i;
  348.             $byte2 = true;
  349.         }
  350.     }
  351.     return $out;
  352. }
  353. //end utf8win1251
  354.  
  355.  
  356. //------------------------------------------------------------------------------------------------
  357. function is_postpaid($msisdn)
  358. {
  359.  /*
  360.    global $PrepaidMMSBilling_db;
  361.    
  362.     $sql = "SELECT count(msisdn) As ok FROM PrepaidMMSBilling.postpaid WHERE msisdn = $msisdn";
  363.     #print $sql."<br>";
  364.     $my_db = new Db ( $PrepaidMMSBilling_db ["host"], $PrepaidMMSBilling_db ["user"], $PrepaidMMSBilling_db ["pass"] );
  365.     $res = & $my_db->execute ( $PrepaidMMSBilling_db ["db"], $sql );
  366.     #print $my_db->error();
  367.     $my_db->close ();
  368.     if ($res [0] ["ok"] > 0)
  369.     {
  370.         return true;
  371.     } else
  372.     {
  373.         return false;
  374.     }
  375.     */
  376.     $result = null;
  377.     $params = new stdClass ();
  378.     $params->RequestHeader = new StdClass ();
  379.     $params->RequestBody = new StdClass ();
  380.  
  381.     $params->RequestBody->Msisdn = $msisdn;
  382.     $params->RequestBody->CheckSubscriberStatus = false;
  383.  
  384.     $service_options = array(
  385.         'soap_version' => 'SOAP_1_2',
  386.         'authentication' => SOAP_AUTHENTICATION_BASIC,
  387.         'features' => SOAP_SINGLE_ELEMENT_ARRAYS,
  388.         'login' => SUBSRIBER_TYPE_SERVICE_USER,
  389.         'password' => SUBSRIBER_TYPE_SERVICE_PASS,
  390.         'encoding' => "utf-8"
  391.     );
  392.  
  393.     try {
  394.  
  395.         $soap_client = new SoapClient (SUBSRIBER_TYPE_SERVICE_WSDL, $service_options);
  396.         $result = $soap_client->GetSubscriberType($params);
  397.     } catch (Exception $exception) {
  398.         var_dump("<pre>", $exception);
  399.         return false;
  400.     }
  401.  
  402.     return $result->ResponseBody->SubscriberType;
  403. }
  404.  
  405. //------------------------------------------------------------------------------------------------
  406. function get_subscriberinfo($msisdn, $sms_id)
  407. {
  408.     global $SMSPrimaRecharge_db, $current_year;
  409.    
  410.     $result = SubscriberInformation ( $msisdn );
  411.    
  412.     $sql = "INSERT INTO SubscriberInfoLog_" . $current_year . "(input_log_id, MSISDN, LogDate, Response) VALUES($sms_id, $msisdn, now(), '" . addslashes ( serialize ( $result ) ) . "')";
  413.     $my_db = new Db ( $SMSPrimaRecharge_db ["host"], $SMSPrimaRecharge_db ["user"], $SMSPrimaRecharge_db ["pass"] );
  414.     $rez = $my_db->execute ( $SMSPrimaRecharge_db ["db"], $sql );
  415.     #print "<pre>"; var_dump($my_db);die;
  416.    $my_db->close ();
  417.    
  418.     return $result;
  419. } //end get_subscriberinfo
  420.  
  421.  
  422. //---------------------------------------------------------------------------------
  423. function is_prepaid($prima, $price, $sms_id)
  424. {
  425.     global $SMSPrimaRecharge_db, $current_year, $stk_flag, $tid, $tiddate;
  426.    
  427.     $params_header = new stdClass ( );
  428.     $params_header->UserName = 'MTELPROD';
  429.     $params_header->Password = 'feldkhun';
  430.    
  431.     if ($stk_flag == 1)
  432.     { # ako stk_flag e 1 polzvam Source 3 - STK, v protiven sluchai 1 - SMS
  433.        $source = 3;
  434.     } else
  435.     {
  436.         $source = 1;
  437.     }
  438.    
  439.     $params = new stdClass ( );
  440.     $params->Source = $source;
  441.     $params->MSISDN = $prima;
  442.     $params->TID = $tid;
  443.     $params->TIDDate = $tiddate;
  444.     $params->Amount = $price;
  445.     $params->Language = 0;
  446.    
  447.     ini_set ( "default_socket_timeout", 10 );
  448.     $soap_client = new SoapClient ( '/home/sms/inc/wsdls/BankInterface.wsdl', array ('trace' => 1, 'connection_timeout' => 5 ) );
  449.    
  450.     $header = new SoapHeader ( 'http://www.mtel.bg', 'SOAPAuthenticationHeader', $params_header );
  451.    
  452.     $soap_client->__setSoapHeaders ( array ($header ) );
  453.    
  454.     try
  455.     {
  456.         $res = $soap_client->CheckPrima ( $params );
  457.     } catch ( SoapFault $exception )
  458.     {
  459.         $res = false;
  460.         $result ["CheckPrimaResult"] = - 1;
  461.         $result ["SOAPStatus"] = $exception->getMessage ();
  462.         $result ["RAmount"] = 0;
  463.         $result ["Source"] = $source;
  464.         $result ["TID"] = $tid;
  465.         $result ["TIDDate"] = $tiddate;
  466.         #return false;
  467.    }
  468.    
  469.     $sql = "INSERT INTO PrimaLog_" . $current_year . "(input_log_id, LogDate, Request, Response) VALUES($sms_id, now(), '" . addslashes ( $soap_client->__getLastRequest () ) . "', '" . addslashes ( $soap_client->__getLastResponse () ) . "')";
  470.     $my_db = new Db ( $SMSPrimaRecharge_db ["host"], $SMSPrimaRecharge_db ["user"], $SMSPrimaRecharge_db ["pass"] );
  471.     $rez = $my_db->execute ( $SMSPrimaRecharge_db ["db"], $sql );
  472.     #print "<pre>"; var_dump($my_db);die;
  473.    $my_db->close ();
  474.    
  475.     if (! $res)
  476.         return $result;
  477.        
  478.     // Return the result
  479.     $result ["CheckPrimaResult"] = $res->CheckPrimaResult;
  480.     $result ["SOAPStatus"] = "OK";
  481.     $result ["RAmount"] = $res->RAmount;
  482.     $result ["Source"] = $source;
  483.     $result ["TID"] = $tid;
  484.     $result ["TIDDate"] = $tiddate;
  485.    
  486.     return $result;
  487. } //end is_prepaid
  488.  
  489.  
  490. //---------------------------------------------------------------------------------
  491. function recharge_prima($prima, $mo_msisdn, $params_arr, $sms_id)
  492. {
  493.     global $SMSPrimaRecharge_db, $current_year;
  494.    
  495.     $params_header = new stdClass ( );
  496.     $params_header->UserName = 'MTELPROD';
  497.     $params_header->Password = 'feldkhun';
  498.    
  499.     $params = new stdClass ( );
  500.     $params->Source = $params_arr ["Source"];
  501.     $params->MSISDN = $prima;
  502.     $params->TID = $params_arr ["TID"];
  503.     $params->TIDDate = $params_arr ["TIDDate"];
  504.     $params->Card = $mo_msisdn;
  505.     $params->Amount = $params_arr ["RAmount"];
  506.     $params->Ref = 0;
  507.    
  508.     ini_set ( "default_socket_timeout", 35 );
  509.     $soap_client = new SoapClient ( '/home/sms/inc/wsdls/BankInterface.wsdl', array ('trace' => 1, 'connection_timeout' => 5 ) );
  510.    
  511.     $header = new SoapHeader ( 'http://www.mtel.bg', 'SOAPAuthenticationHeader', $params_header );
  512.    
  513.     $soap_client->__setSoapHeaders ( array ($header ) );
  514.    
  515.     try
  516.     {
  517.         $res = $soap_client->PayPrima ( $params );
  518.     } catch ( SoapFault $exception )
  519.     {
  520.         #don't return here result must be logged into DB
  521.    #return false;
  522.    }
  523.    
  524.     $sql = "INSERT INTO PrimaLog_" . $current_year . "(input_log_id, LogDate, Request, Response) VALUES($sms_id, now(), '" . addslashes ( $soap_client->__getLastRequest () ) . "', '" . addslashes ( $soap_client->__getLastResponse () ) . "')";
  525.     $my_db = new Db ( $SMSPrimaRecharge_db ["host"], $SMSPrimaRecharge_db ["user"], $SMSPrimaRecharge_db ["pass"] );
  526.     $rez = $my_db->execute ( $SMSPrimaRecharge_db ["db"], $sql );
  527.     #print "<pre>"; var_dump($my_db);die;
  528.    $my_db->close ();
  529.    
  530.     if (isset ( $res->PayPrimaResult ) && ($res->PayPrimaResult == 0))
  531.         return true;
  532.     else
  533.         return false;
  534. } //end recharge_prima
  535.  
  536.  
  537. //-------------------------------------------------------------------------------
  538.  
  539.  
  540. /**
  541.  * Function call TIBCO web service
  542.  * in order to register service in
  543.  * CRM Automatic Notification tab
  544.  *
  545.  * @param unknown_type $msisdn - gsm number
  546.  * @param unknown_type $short_number - short number
  547.  * @param unknown_type $sms_text - text of the message
  548.  * @param unknown_type $message_id - sms id value
  549.  * @return boolean  
  550.  */
  551. function register_mt_to_crm($msisdn, $short_number, $sms_text, $message_id)
  552. {
  553.     $msisdn = '0' . substr ( $msisdn, 3 );
  554.    
  555.     $service_options = array ('soap_version' => 'SOAP_1_2', 'authentication' => SOAP_AUTHENTICATION_BASIC, 'User-Agent' => 'User-Agent: Jakarta Commons-HttpClient/3.1', 'trace' => 1, 'exceptions' => true, 'cache_wsdl' => WSDL_CACHE_NONE, 'features' => SOAP_SINGLE_ELEMENT_ARRAYS, 'login' => SUBSCRIBER_MESSAGING_LOGIN, 'password' => SUBSCRIBER_MESSAGING_PASSWORD, 'location' => SUBSCRIBER_MESSAGING_LOCATION, 'uri' => "http://mtel.bg/SubscriberMessaging/BusinessServices/MessagingService", 'encoding' => "utf-8", 'connection_timeout' => 10 );
  556.    
  557.     $params = new stdClass ( );
  558.     $params->InterfaceRequestHeader = new StdClass ( ); # * empty tibco header
  559.    $params->RequestBody = new StdClass ( );
  560.    
  561.     # MessageID must be unique, so use "dma_" application name unique_id (max length 20)
  562.    $params->RequestBody->MessageID = SUBSCRIBER_MESSAGING_SERVICE_UNIQUE_ID . '_' . $message_id;
  563.     # CorrelationID is used for mapping with sms_delivery_report.delivery_report_id
  564.    $params->RequestBody->CorrelationID = SUBSCRIBER_MESSAGING_SERVICE_UNIQUE_ID . '_' . $message_id;
  565.     $params->RequestBody->Sender = $short_number;
  566.     $params->RequestBody->Receiver = $msisdn;
  567.     $params->RequestBody->Priority = 0;
  568.     # options are Text, WAP-Push, MMS
  569.    $params->RequestBody->PayloadType = 'Text';
  570.     $params->RequestBody->StartDate = date ( "c", time () );
  571.     $params->RequestBody->EndDate = date ( "c", time () );
  572.     $params->RequestBody->Text = $sms_text;
  573.     # SMSC or MMSC
  574.    $params->RequestBody->BackEnd = 'SMSC';
  575.     #
  576.    $params->RequestBody->SchedulerTemplate = 'WeekDays';
  577.     $params->RequestBody->Status = 'Sent'; # Delivered
  578.    
  579.     # Marin Bodichev for more information
  580.    $params->RequestBody->TemplateID = 'SMSGEN'; # SASCM1
  581.    
  582.     try
  583.     {
  584.         //@error_log ( var_export ( $params, true ), 3, '/tmp/1616_6lv_voucher.log' );
  585.  
  586.         $soap_client = new SoapClient ( SUBSCRIBER_MESSAGING_WSDL, $service_options );
  587.         $result = $soap_client->InsertSMSLog ( $params );
  588.        // @error_log ( var_export ( $result, true ), 3, '/tmp/1616_6lv_voucher.log' );
  589.     } catch ( Exception $exception )
  590.     {
  591.         //@error_log ( var_export ( $exception, true ), 3, '/tmp/1616_6lv_voucher.log' );
  592.         return false;
  593.     }
  594.    
  595.     debugLog($service_options);
  596.     debugLog($params);
  597.     debugLog($result);
  598.    
  599.     return $result->RequestBody->returnMsg;
  600. }
  601.  
  602. function debugLog($sting)
  603. {
  604.     //@error_log (  var_export($sting, true), 3, '/tmp/1616_6lv_voucher.log' );
  605. }
  606.  
  607.  
  608. /*
  609. all params are (with example values):
  610.  
  611. if (!isset($origin)){
  612.     $stype="";
  613.     $origin="11359888618754";
  614.     $destination="311616";
  615.     $class=0;
  616.     $pid=0;
  617.     $priority=0;
  618.     $dcs=0;
  619.     $smtext="0886218875,10";
  620. }
  621. */
  622.  
  623.  
  624. //if(!isset($_GET["test_web"])) exit("Interface not permitted.");
  625. //if($_GET["info"]=="true") exit("Params:test_web; sender (postpaid msisdn), text (prepaid_msisdn,recharge_sum); Example: ?test_web&sender=+359882203685&text=0888123123,10");
  626. $gsmnum = substr ( $_GET ["sender"], 1 );
  627. $input = trim ( urldecode ( $_GET ["text"] ) );
  628.  
  629. #$original_input = $input;
  630. $sum = 0;
  631. $prima = 0;
  632.  
  633. if ($_GET ["charset"] != "ISO-8859-1")
  634. {
  635.     $input = iconv ( $_GET ["charset"], 'windows-1251//IGNORE', $input );
  636. }
  637.  
  638. $input = strtolower ( $input );
  639.  
  640. $sms_id = log_em_all ( $destination, $gsmnum, $input );
  641.  
  642. #skip spaces
  643. $input = str_replace ( " ", "", $input );
  644.  
  645. $tidtime = time ();
  646. $tiddate = date ( "Y-m-d", $tidtime ) . 'T' . date ( "H:i:s", $tidtime );
  647.  
  648.  
  649. # GLB  
  650. if (preg_match ( '/^stop$/i', strtolower ( $input ) ))
  651. {
  652.     ini_set ( "default_socket_timeout", 5 );
  653.     ini_set ( "soap.wsdl_cache_enabled", 1 );
  654.    
  655.     $input = new stdClass ( );
  656.     $input->auth->username          = GBL_SERVICE_USER;
  657.     $input->auth->password          = GBL_SERVICE_PASS;
  658.     $input->channel->channelName    = GBL_SERVICE_CHANNEL;
  659.     $input->category->categoryName  = GBL_SERVICE_CATEGORY;
  660.     $input->service->serviceName    = "1616";
  661.     $input->a_party                 = "mtel";
  662.     $input->b_party                 = "msisdn_{$gsmnum}";
  663.  
  664.     try
  665.     {
  666.         $soap_client = new SoapClient ( GBL_SERVICE_WSDL, array ("connection_timeout" => 5 ) );
  667.         $result = $soap_client->addBlock ( $input );
  668.     } catch ( SoapFault $exception )
  669.     {
  670.    
  671.     }
  672.    
  673.     debugLog($input);
  674.     debugLog($soap_client);
  675.     debugLog($result);
  676.    
  677.     sendsms ( M12, $gsmnum, $sms_id);
  678.     exit ();
  679. }
  680.  
  681. # 18.01.2012 STK channel have to handle 5 lv and 6 lv vaucher,
  682. # while SMS channel must handle only 6 lv voucher (i.stoyanov@mobiltel.bg)
  683. #miro 20131004
  684. //if (! preg_match_all ( "/^(08[7-9]{1}[0-9]{1}[0-9]{6}),((6|06|10|15{1})|(5|05|6|06|10|15)(,stk))$/", $input, $matches ))
  685. if (! preg_match_all ( "/^(0[8-9]{1}[7-9]{1}[0-9]{1}[0-9]{6}),((6|06|10|15{1})|(5|05|6|06|10|15)(,stk))$/", $input, $matches ))
  686. //if (! preg_match_all ( "/^(08[7-9]{1}[2-9]{1}[0-9]{6}),(5|05|10|15{1})(,stk)?$/", $input, $matches ))
  687. {
  688.     //if (!preg_match_all("/^(08[7-9]{1}[2-9]{1}[0-9]{6}),(5|05|6|06|10|15{1})(,stk)?$/", $input, $matches)){
  689.     #mail('jgmec@mtel.net', 'SMS Error', '<pre>' .print_r($matches, true). '</pre>');
  690.    $tid = date ( "YmdHis", $tidtime ) . '01' . str_pad ( $sms_id, 10, '0', STR_PAD_LEFT );
  691. #    $my_bam = new BAM ( $tid, 'SMS1616', 'prod', 'SMS' );
  692. #    $my_bam->SendEvent ( 'SMSGW', 'SMS Received', array ('Step' => 'end', 'RequestID' => $sms_id, 'MSISDNPrepaid' => 'Unknown', 'MSISDNPostpaid' => '+' . $gsmnum, 'RAmount' => ($sum * 100), 'State' => 'OK', 'SME number' => $_GET ["receiver"], 'SMS tstamp' => date ( "Y-m-d H:i:s", $_GET ["tstamp"] ), 'In SMS Message' => iconv ( 'windows-1251', 'UTF-8//IGNORE', $input ), 'RequestDateTime' => $my_bam->udate ( "Y-m-d H:i:s.u" ) ) );
  693. #    $my_bam->SendEvent ( 'SMS PRIMA Recharge Application', 'SMS Syntax Check', array ('Step' => 'start', 'RequestID' => $sms_id, 'MSISDNPrepaid' => 'Unknown', 'MSISDNPostpaid' => '+' . $gsmnum, 'RAmount' => ($sum * 100), 'State' => 'OK', 'RequestDateTime' => $my_bam->udate ( "Y-m-d H:i:s.u" ) ) );
  694. #    $my_bam->SendEvent ( 'SMS PRIMA Recharge Application', 'SMS Syntax Check', array ('Step' => 'end', 'RequestID' => $sms_id, 'MSISDNPrepaid' => 'Unknown', 'MSISDNPostpaid' => '+' . $gsmnum, 'RAmount' => ($sum * 100), 'State' => 'NOTOK', 'RequestDateTime' => $my_bam->udate ( "Y-m-d H:i:s.u" ) ) );
  695.    #$my_bam->SendEvent('SMS PRIMA Recharge Application', 'SMS Syntax Not Valid', array('Step'=>'end', 'RequestID'=>$sms_id, 'MSISDNPrepaid'=>'Unknown', 'MSISDNPostpaid'=>'+'.$gsmnum, 'RAmount'=>($sum*100), 'State'=>'NOTOK', 'Out SMS Message' => M1, 'RequestDateTime' => $my_bam->udate("Y-m-d H:i:s.u")));
  696.    $sql = "SELECT `postpaid_msisdn` as msisdn FROM `CRMRechargeCampaigns` WHERE `postpaid_msisdn`='{$gsmnum}'";
  697.     $my_db = new Db ( $SMSPrimaRecharge_db ["host"], $SMSPrimaRecharge_db ["user"], $SMSPrimaRecharge_db ["pass"] );
  698.     $res = & $my_db->execute ( $SMSPrimaRecharge_db ["db"], $sql );
  699.     $my_db->close ();
  700.    
  701.     if (! empty ( $res [0] ["msisdn"] ))
  702.     {
  703.         #ima
  704.        sendsms ( M13, $gsmnum, $sms_id );
  705.     } else
  706.     {
  707.         #niama
  708.        sendsms ( M1, $gsmnum, $sms_id );
  709.     }
  710.     die ();
  711. } else
  712. {
  713.     #var_dump($matches);
  714.    $prima = $matches [1] [0];
  715.     $sum = ( int ) $matches [2] [0];
  716.     $stk_flag = ($matches [5] [0] == ",stk") ? 1 : 0;
  717.     $channel = ($matches [5] [0] == ",stk") ? 'STK' : 'SMS';
  718.    
  719.     debugLog($prima);
  720.     debugLog($sum);
  721.     debugLog($channel);
  722.    
  723.     # New feature. Start pico-push script for update STK menu, so clients
  724.    # to be able to use new 6 lv voucher via STK channel
  725.    # date 18.01.2012 i.stoyanov@mobiltel.bg
  726.    if ($channel == 'STK' and $sum == 5)
  727.     {
  728.         $service_options = array ('soap_version' => 'SOAP_1_2',
  729.             'authentication' => SOAP_AUTHENTICATION_BASIC,  
  730.             'trace'          => 1,
  731.             'exceptions'     => true,
  732.             'cache_wsdl'     => WSDL_CACHE_MEMORY, # WSDL_CACHE_NONE
  733.            'login'          => PICO_PUSH_LOGIN,
  734.             'password'       => PICO_PUSH_USER,
  735.             'encoding'       => "utf-8",
  736.             'connection_timeout' => 3 );
  737.        
  738.         # call pico-push service
  739.        try{
  740.             $soap = new SoapClient(PICO_PUSH_WSDL, $service_options);
  741.             $params             = new StdClass();
  742.             $params->to_msisdn  = $gsmnum;
  743.             $params->page       = PICO_PUSH_PAGE;
  744.             $params->text       = M14;
  745.             #use web service of mtel contact
  746.            $res                = $soap->sendPage($params);
  747.             #$res == "200 OK" SIM card is supported, not supported in other cases
  748.            
  749.             debugLog($service_options);
  750.             debugLog($params);
  751.             debugLog($res);
  752.            
  753.             if ($res == '200 OK')
  754.             {  
  755.                 #STK platform start communication with msisdn
  756.                log_sent($gsmnum, M14, $sms_id );
  757.                 exit;
  758.             }
  759.         }catch(Exception $exception){
  760.             //var_dump($exception);
  761.             debugLog($exception->getMessage());
  762.         }
  763.     }
  764.    
  765.    
  766.    
  767.     if ($stk_flag == 1)
  768.     { # ako stk_flag e 1 polzvam Source 3 - STK, v protiven sluchai 1 - SMS
  769.        $tid = date ( "YmdHis", $tidtime ) . '03' . str_pad ( $sms_id, 10, '0', STR_PAD_LEFT );
  770.     } else
  771.     {
  772.         $tid = date ( "YmdHis", $tidtime ) . '01' . str_pad ( $sms_id, 10, '0', STR_PAD_LEFT );
  773.     }
  774. #    $my_bam = new BAM ( $tid, 'SMS1616', 'prod', $channel );
  775. #    $my_bam->SendEvent ( 'SMSGW', 'SMS Received', array ('Step' => 'end', 'RequestID' => $sms_id, 'MSISDNPrepaid' => "+359" . substr ( $prima, 1 ), 'MSISDNPostpaid' => '+' . $gsmnum, 'RAmount' => ($sum * 100), 'State' => 'OK', 'SME number' => $_GET ["receiver"], 'SMS tstamp' => date ( "Y-m-d H:i:s", $_GET ["tstamp"] ), 'In SMS Message' => iconv ( 'windows-1251', 'UTF-8//IGNORE', $input ), 'RequestDateTime' => $my_bam->udate ( "Y-m-d H:i:s.u" ) ) );
  776. #    $my_bam->SendEvent ( 'SMS PRIMA Recharge Application', 'SMS Syntax Check', array ('Step' => 'start', 'RequestID' => $sms_id, 'MSISDNPrepaid' => "+359" . substr ( $prima, 1 ), 'MSISDNPostpaid' => '+' . $gsmnum, 'RAmount' => ($sum * 100), 'State' => 'OK', 'RequestDateTime' => $my_bam->udate ( "Y-m-d H:i:s.u" ) ) );
  777. #    $my_bam->SendEvent ( 'SMS PRIMA Recharge Application', 'SMS Syntax Check', array ('Step' => 'end', 'RequestID' => $sms_id, 'MSISDNPrepaid' => "+359" . substr ( $prima, 1 ), 'MSISDNPostpaid' => '+' . $gsmnum, 'RAmount' => ($sum * 100), 'State' => 'OK', 'RequestDateTime' => $my_bam->udate ( "Y-m-d H:i:s.u" ) ) );
  778. }
  779.  
  780. #$my_bam->SendEvent ( 'Postpaid Check DB', 'Postpaid Validity Check', array ('Step' => 'start', 'RequestID' => $sms_id, 'MSISDNPrepaid' => "+359" . substr ( $prima, 1 ), 'MSISDNPostpaid' => '+' . $gsmnum, 'RAmount' => ($sum * 100), 'State' => 'OK', 'RequestDateTime' => $my_bam->udate ( "Y-m-d H:i:s.u" ) ) );
  781.  
  782. //@error_log ( 'is_postpaid for gsm: '. $gsmnum . is_postpaid ( $gsmnum )."\n", 3, '/tmp/1616_6lv_voucher.log' );
  783.  
  784. if (! is_postpaid ( $gsmnum ))
  785. {
  786.     #$my_bam->SendEvent ( 'Postpaid Check DB', 'Postpaid Validity Check', array ('Step' => 'end', 'RequestID' => $sms_id, 'MSISDNPrepaid' => "+359" . substr ( $prima, 1 ), 'MSISDNPostpaid' => '+' . $gsmnum, 'RAmount' => ($sum * 100), 'State' => 'NOTOK', 'StatusDescription' => 'Number not found in Postpaid Check DB.', 'Out SMS Message' => M3, 'RequestDateTime' => $my_bam->udate ( "Y-m-d H:i:s.u" ) ) );
  787.    sendsms ( M3, $gsmnum, $sms_id );
  788.     die ();
  789. } else
  790. {
  791.     #$my_bam->SendEvent ( 'Postpaid Check DB', 'Postpaid Validity Check', array ('Step' => 'end', 'RequestID' => $sms_id, 'MSISDNPrepaid' => "+359" . substr ( $prima, 1 ), 'MSISDNPostpaid' => '+' . $gsmnum, 'RAmount' => ($sum * 100), 'State' => 'OK', 'RequestDateTime' => $my_bam->udate ( "Y-m-d H:i:s.u" ) ) );
  792. }
  793.  
  794. #$my_bam->SendEvent ( 'TIBCO', 'Postpaid Recharge Service Allowance Check', array ('Step' => 'start', 'RequestID' => $sms_id, 'MSISDNPrepaid' => "+359" . substr ( $prima, 1 ), 'MSISDNPostpaid' => '+' . $gsmnum, 'RAmount' => ($sum * 100), 'State' => 'OK', 'RequestDateTime' => $my_bam->udate ( "Y-m-d H:i:s.u" ) ) );
  795. $subscriberinfo = get_subscriberinfo ( $gsmnum, $sms_id );
  796.  
  797. debugLog($subscriberinfo);
  798.  
  799. if (! $subscriberinfo || count ( $subscriberinfo ) < 1)
  800. {
  801.     #$my_bam->SendEvent ( 'TIBCO', 'Postpaid Recharge Service Allowance Check', array ('Step' => 'end', 'RequestID' => $sms_id, 'MSISDNPrepaid' => "+359" . substr ( $prima, 1 ), 'MSISDNPostpaid' => '+' . $gsmnum, 'RAmount' => ($sum * 100), 'State' => 'NOTOK', 'StatusDescription' => 'SubscriberInformation error. Error Fetching http headers.', 'Out SMS Message' => M9, 'RequestDateTime' => $my_bam->udate ( "Y-m-d H:i:s.u" ) ) );
  802.    sendsms ( M9, $gsmnum, $sms_id );
  803.     die ();
  804. }
  805.  
  806. //@error_log ( 'check_flood:' . check_flood ( $gsmnum ), 3, '/tmp/1616_6lv_voucher.log' );
  807.  
  808. if ($subscriberinfo ["primarechargeunlimited"] == "No" && check_flood ( $gsmnum ))
  809. {
  810.     #$my_bam->SendEvent ( 'TIBCO', 'Postpaid Recharge Service Allowance Check', array ('Step' => 'end', 'RequestID' => $sms_id, 'MSISDNPrepaid' => "+359" . substr ( $prima, 1 ), 'MSISDNPostpaid' => '+' . $gsmnum, 'RAmount' => ($sum * 100), 'State' => 'NOTOK', 'StatusDescription' => 'Recharge limit reached - 1 per hour 2 per day', 'Out SMS Message' => M2, 'RequestDateTime' => $my_bam->udate ( "Y-m-d H:i:s.u" ) ) );
  811.    sendsms ( M2, $gsmnum, $sms_id );
  812.     die ();
  813. }
  814.  
  815. if ((( int ) $subscriberinfo ["primary_id"] < 1) || (( int ) $subscriberinfo ["status"] != 1))
  816. {
  817.     #$my_bam->SendEvent ( 'TIBCO', 'Postpaid Recharge Service Allowance Check', array ('Step' => 'end', 'RequestID' => $sms_id, 'MSISDNPrepaid' => "+359" . substr ( $prima, 1 ), 'MSISDNPostpaid' => '+' . $gsmnum, 'RAmount' => ($sum * 100), 'State' => 'NOTOK', 'StatusDescription' => 'Not a valid postpaid number or inactive status.', 'Out SMS Message' => M3, 'RequestDateTime' => $my_bam->udate ( "Y-m-d H:i:s.u" ) ) );
  818.    sendsms ( M3, $gsmnum, $sms_id );
  819.     die ();
  820. }
  821.  
  822. if ($subscriberinfo ["recharge_allowed"] != "Yes")
  823. {
  824.     #$my_bam->SendEvent ( 'TIBCO', 'Postpaid Recharge Service Allowance Check', array ('Step' => 'end', 'RequestID' => $sms_id, 'MSISDNPrepaid' => "+359" . substr ( $prima, 1 ), 'MSISDNPostpaid' => '+' . $gsmnum, 'RAmount' => ($sum * 100), 'State' => 'NOTOK', 'StatusDescription' => 'SMS Prima Recharge not allowed.', 'Out SMS Message' => M10, 'RequestDateTime' => $my_bam->udate ( "Y-m-d H:i:s.u" ) ) );
  825.    sendsms ( M10, $gsmnum, $sms_id );
  826.     die ();
  827. }
  828.  
  829. if ($subscriberinfo ["subscriber_type"] != "Business" && strtotime ( substr ( $subscriberinfo ["effective_date_from3"], 0, 10 ) ) > mktime ( 0, 0, 0, date ( "m" ) - 3, date ( "d" ), date ( "Y" ) ))
  830. {
  831. #    $my_bam->SendEvent ( 'TIBCO', 'Postpaid Recharge Service Allowance Check', array ('Step' => 'end', 'RequestID' => $sms_id, 'MSISDNPrepaid' => "+359" . substr ( $prima, 1 ), 'MSISDNPostpaid' => '+' . $gsmnum, 'RAmount' => ($sum * 100), 'State' => 'NOTOK', 'StatusDescription' => 'Residential subscriber without 3 months of history.', 'Out SMS Message' => M4, 'RequestDateTime' => $my_bam->udate ( "Y-m-d H:i:s.u" ) ) );
  832.    sendsms ( M4, $gsmnum, $sms_id );
  833.     die ();
  834. }
  835.  
  836. if (((( float ) $subscriberinfo ["non_billed_balance"] + ( float ) $sum) > (( float ) $subscriberinfo ["credit_limit"] + ( float ) $subscriberinfo ["subscriber_deposit"])) && ($subscriberinfo ["usage_never_stop"] == "No"))
  837. {
  838. #    $my_bam->SendEvent ( 'TIBCO', 'Postpaid Recharge Service Allowance Check', array ('Step' => 'end', 'RequestID' => $sms_id, 'MSISDNPrepaid' => "+359" . substr ( $prima, 1 ), 'MSISDNPostpaid' => '+' . $gsmnum, 'RAmount' => ($sum * 100), 'State' => 'NOTOK', 'StatusDescription' => 'Not enough balance/credit limit.', 'Out SMS Message' => M5, 'RequestDateTime' => $my_bam->udate ( "Y-m-d H:i:s.u" ) ) );
  839.    sendsms ( M5, $gsmnum, $sms_id );
  840.     die ();
  841. }
  842.  
  843. #$my_bam->SendEvent ( 'SMS PRIMA Recharge Application', 'Prepaid Validity Check', array ('Step' => 'start', 'RequestID' => $sms_id, 'MSISDNPrepaid' => "+359" . substr ( $prima, 1 ), 'MSISDNPostpaid' => '+' . $gsmnum, 'RAmount' => ($sum * 100), 'State' => 'OK', 'RequestDateTime' => $my_bam->udate ( "Y-m-d H:i:s.u" ) ) );
  844.  
  845. $check_prima = is_prepaid ( "359" . substr ( $prima, 1 ), ($sum * 100), $sms_id );
  846.  
  847. if ($check_prima ["CheckPrimaResult"] == - 1)
  848. { #some error occurred with WS call
  849.    #$my_bam->SendEvent ( 'TIBCO', 'Postpaid Recharge Service Allowance Check', array ('Step' => 'end', 'RequestID' => $sms_id, 'MSISDNPrepaid' => "+359" . substr ( $prima, 1 ), 'MSISDNPostpaid' => '+' . $gsmnum, 'RAmount' => ($sum * 100), 'State' => 'OK', 'RequestDateTime' => $my_bam->udate ( "Y-m-d H:i:s.u" ) ) );
  850.    #$my_bam->SendEvent ( 'SMS PRIMA Recharge Application', 'Prepaid Validity Check', array ('Step' => 'end', 'RequestID' => $sms_id, 'MSISDNPrepaid' => "+359" . substr ( $prima, 1 ), 'MSISDNPostpaid' => '+' . $gsmnum, 'RAmount' => ($sum * 100), 'State' => 'NOTOK', 'StatusDescription' => 'Error during Prepaid Check. ' . $check_prima ["SOAPStatus"], 'Out SMS Message' => M9, 'RequestDateTime' => $my_bam->udate ( "Y-m-d H:i:s.u" ) ) );
  851.    sendsms ( M9, $gsmnum, $sms_id );
  852.     die ();
  853. } else
  854. {
  855.     #$my_bam->SendEvent ( 'SMS PRIMA Recharge Application', 'Prepaid Validity Check', array ('Step' => 'end', 'RequestID' => $sms_id, 'MSISDNPrepaid' => "+359" . substr ( $prima, 1 ), 'MSISDNPostpaid' => '+' . $gsmnum, 'RAmount' => ($sum * 100), 'State' => 'OK', 'RequestDateTime' => $my_bam->udate ( "Y-m-d H:i:s.u" ) ) );
  856. }
  857.  
  858. if ($check_prima ["CheckPrimaResult"] != 0)
  859. { #not a valid prima
  860. #    $my_bam->SendEvent ( 'TIBCO', 'Postpaid Recharge Service Allowance Check', array ('Step' => 'end', 'RequestID' => $sms_id, 'MSISDNPrepaid' => "+359" . substr ( $prima, 1 ), 'MSISDNPostpaid' => '+' . $gsmnum, 'RAmount' => ($sum * 100), 'State' => 'OK', 'RequestDateTime' => $my_bam->udate ( "Y-m-d H:i:s.u" ) ) );
  861. #    $my_bam->SendEvent ( 'SMS PRIMA Recharge Application', 'Prepaid Validity Check', array ('Step' => 'end', 'RequestID' => $sms_id, 'MSISDNPrepaid' => "+359" . substr ( $prima, 1 ), 'MSISDNPostpaid' => '+' . $gsmnum, 'RAmount' => ($sum * 100), 'State' => 'NOTOK', 'StatusDescription' => 'Prepaid recharge not possible - ' . $bank_api_codes [$check_prima ["CheckPrimaResult"]], 'Out SMS Message' => M6, 'RequestDateTime' => $my_bam->udate ( "Y-m-d H:i:s.u" ) ) );
  862.    sendsms ( M6, $gsmnum, $sms_id );
  863.     die ();
  864. }
  865.  
  866. #added for very fast SMS senders:)))
  867. if (check_parallel_transaction ( $gsmnum, $sms_id ))
  868. {
  869.     sleep ( mt_rand ( 20, 30 ) ); #wait between 20 and 30 seconds
  870. }
  871.  
  872. #added for fast SMS senders:)))))
  873. if ($subscriberinfo ["primarechargeunlimited"] == "No" && check_flood ( $gsmnum ))
  874. {
  875. #    $my_bam->SendEvent ( 'TIBCO', 'Postpaid Recharge Service Allowance Check', array ('Step' => 'end', 'RequestID' => $sms_id, 'MSISDNPrepaid' => "+359" . substr ( $prima, 1 ), 'MSISDNPostpaid' => '+' . $gsmnum, 'RAmount' => ($sum * 100), 'State' => 'NOTOK', 'StatusDescription' => 'Recharge limit reached - 1 per hour 2 per day', 'Out SMS Message' => M2, 'RequestDateTime' => $my_bam->udate ( "Y-m-d H:i:s.u" ) ) );
  876.    sendsms ( M2, $gsmnum, $sms_id );
  877.     die ();
  878. } else
  879. {
  880. #    $my_bam->SendEvent ( 'TIBCO', 'Postpaid Recharge Service Allowance Check', array ('Step' => 'end', 'RequestID' => $sms_id, 'MSISDNPrepaid' => "+359" . substr ( $prima, 1 ), 'MSISDNPostpaid' => '+' . $gsmnum, 'RAmount' => ($sum * 100), 'State' => 'OK', 'RequestDateTime' => $my_bam->udate ( "Y-m-d H:i:s.u" ) ) );
  881. }
  882.  
  883. #$my_bam->SendEvent ( 'SMS PRIMA Recharge Application', 'Prepaid Recharge Request', array ('Step' => 'start', 'RequestID' => $sms_id, 'MSISDNPrepaid' => "+359" . substr ( $prima, 1 ), 'MSISDNPostpaid' => '+' . $gsmnum, 'RAmount' => ($sum * 100), 'Amount' => $check_prima ["RAmount"], 'State' => 'OK', 'RequestDateTime' => $my_bam->udate ( "Y-m-d H:i:s.u" ) ) );
  884.  
  885.  
  886. # miroslav biliarski 2013-10-04
  887. # OnProd Comment this 3 lines !!
  888. #echo "Test ok";
  889. #echo "Rrecharge_prima ( \"359\" . substr ( $prima, 1 ), $gsmnum, $check_prima, $sms_id )";
  890. #exit(0);
  891.  
  892.  
  893. if (recharge_prima ( "359" . substr ( $prima, 1 ), $gsmnum, $check_prima, $sms_id ))
  894. { #request is accepted
  895. #    $my_bam->SendEvent ( 'SMS PRIMA Recharge Application', 'Prepaid Recharge Request', array ('Step' => 'end', 'RequestID' => $sms_id, 'MSISDNPrepaid' => "+359" . substr ( $prima, 1 ), 'MSISDNPostpaid' => '+' . $gsmnum, 'RAmount' => ($sum * 100), 'Amount' => $check_prima ["RAmount"], 'State' => 'OK', 'RequestDateTime' => $my_bam->udate ( "Y-m-d H:i:s.u" ) ) );
  896.    #$my_bam->SendEvent('TIBCO', 'Recharge Request Pre-Processing', array('Step'=>'end', 'RequestID'=>$sms_id, 'MSISDNPrepaid'=>"+359".substr($prima, 1), 'MSISDNPostpaid'=>'+'.$gsmnum, 'RAmount'=>($sum*100), 'Amount'=>$check_prima["RAmount"], 'State'=>'OK'));
  897.    make_PrimaRechargeHistory ( $gsmnum, $prima, $sum, $sms_id, $subscriberinfo ["primary_id"], substr ( $check_prima ["TID"], 0, 14 ));
  898.     #make CDR
  899. #    $my_bam->SendEvent ( 'CDR DB', 'Postpaid CDR Generation', array ('Step' => 'start', 'RequestID' => $sms_id, 'MSISDNPrepaid' => "+359" . substr ( $prima, 1 ), 'MSISDNPostpaid' => '+' . $gsmnum, 'RAmount' => ($sum * 100), 'Amount' => $check_prima ["RAmount"], 'State' => 'OK', 'RequestDateTime' => $my_bam->udate ( "Y-m-d H:i:s.u" ) ) );
  900.    if (make_cdr ( $gsmnum, $prima, $sum, $check_prima ["RAmount"], substr ( $check_prima ["TID"], 0, 14 ) ))
  901.     {
  902. #        $my_bam->SendEvent ( 'CDR DB', 'Postpaid CDR Generation', array ('Step' => 'end', 'RequestID' => $sms_id, 'MSISDNPrepaid' => "+359" . substr ( $prima, 1 ), 'MSISDNPostpaid' => '+' . $gsmnum, 'RAmount' => ($sum * 100), 'Amount' => $check_prima ["RAmount"], 'State' => 'OK', 'Out SMS Message' => M7 . $prima . M71 . $sum . M72, 'RequestDateTime' => $my_bam->udate ( "Y-m-d H:i:s.u" ) ) );
  903.    } else
  904.     {
  905. #        $my_bam->SendEvent ( 'CDR DB', 'Postpaid CDR Generation', array ('Step' => 'end', 'RequestID' => $sms_id, 'MSISDNPrepaid' => "+359" . substr ( $prima, 1 ), 'MSISDNPostpaid' => '+' . $gsmnum, 'RAmount' => ($sum * 100), 'Amount' => $check_prima ["RAmount"], 'State' => 'NOTOK', 'StatusDescription' => 'CDR Not recorded.', 'Out SMS Message' => M7 . $prima . M71 . $sum . M72, 'RequestDateTime' => $my_bam->udate ( "Y-m-d H:i:s.u" ) ) );
  906.    }
  907.    
  908.     #send SMS notification
  909.    sendsms ( M7 . $prima . M71 . $sum . M72, $gsmnum, $sms_id );
  910.     die ();
  911. } else
  912. { #some error occurred
  913. #    $my_bam->SendEvent ( 'SMS PRIMA Recharge Application', 'Prepaid Recharge Request', array ('Step' => 'end', 'RequestID' => $sms_id, 'MSISDNPrepaid' => "+359" . substr ( $prima, 1 ), 'MSISDNPostpaid' => '+' . $gsmnum, 'RAmount' => ($sum * 100), 'Amount' => $check_prima ["RAmount"], 'State' => 'NOTOK', 'StatusDescription' => 'Recharge not accepted', 'Out SMS Message' => M9, 'RequestDateTime' => $my_bam->udate ( "Y-m-d H:i:s.u" ) ) );
  914.    sendsms ( M9, $gsmnum, $sms_id );
  915.     die ();
  916. }
  917. die ();
  918.  
  919. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement