biztalk.php 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  1. <?php
  2. class Biztalk {
  3. private $smsurl = 'https://www.biztalk-api.com/v2/kko/sendAlimTalk';
  4. private $resulturl = 'https://www.biztalk-api.com/v2/kko/getResultAll';
  5. private $token_url = 'https://www.biztalk-api.com/v2/auth/getToken';
  6. private $bsid = "esmotors2300";
  7. private $passwd = "d8ad437905f0e52f147ae055c3690b731e5345b4";
  8. private $schema = "";
  9. private $accessToken = "";
  10. private $destinations = array();
  11. function __construct() {
  12. }
  13. /*
  14. Constructor
  15. @param
  16. */
  17. function Biztalk(){
  18. }
  19. /*
  20. Set the devices to send to
  21. @param $deviceIds array of device tokens to send to
  22. */
  23. function setDestination($destinations){
  24. $dest = array();
  25. if(!is_array($destinations)){
  26. $destinations = array($destinations);
  27. }
  28. foreach ($destinations as $key => $value) {
  29. $dest[]['to'] = replace_phone_infobank($value);
  30. }
  31. // print_r($dest);
  32. // print_r($destinations);
  33. $this->destinations = $dest;
  34. }
  35. function setToken($token){
  36. // $this->accessToken = $token;
  37. }
  38. /*
  39. Send the message to the device
  40. @param $message The message to send
  41. @param $data Array of data to accompany the message
  42. */
  43. function getToken(){
  44. $headers = array(
  45. //'X-IB-Client-Id: ' . $this->serviceId,
  46. //'X-IB-Client-Passwd: ' . $this->servicePassword,
  47. 'Content-Type: application/json',
  48. 'Accept: application/json'
  49. );
  50. $data = "{ 'bsid' : $this->bsid, 'passwd' => $this->passwd }";
  51. // Open connection
  52. $ch = curl_init();
  53. // Set the url, number of POST vars, POST data
  54. curl_setopt( $ch, CURLOPT_URL, $this->token_url );
  55. curl_setopt( $ch, CURLOPT_POST, true );
  56. curl_setopt( $ch, CURLOPT_HTTPHEADER, $headers);
  57. curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
  58. // echo json_encode(array($data));
  59. curl_setopt( $ch, CURLOPT_POSTFIELDS, $data );
  60. $info = curl_getinfo($ch);
  61. // Execute post
  62. $result = curl_exec($ch);
  63. // echo json_encode($data);
  64. // print_r($info);
  65. // var_dump($result); //결과 값 출력
  66. // print_r(curl_getinfo($ch)); //모든 정보 출력
  67. // Close connection
  68. curl_close($ch);
  69. $result = json_decode($result, true);
  70. // $this->schema = $result['schema'];
  71. $this->accessToken = $result['token'];
  72. }
  73. /*
  74. Send the message to the device
  75. @param $message The message to send
  76. @param $data Array of data to accompany the message
  77. */
  78. function sendSms($data){
  79. return ;
  80. $fields = array(
  81. 'msgIdx' => uniqid("upro"),
  82. 'countryCode' => "82"
  83. );
  84. // print_r($fields);
  85. // exit;
  86. $debug = "N";
  87. if($data['debug'] == "Y") {
  88. $debug = "Y";
  89. unset($data['debug']);
  90. }
  91. if(is_array($data)){
  92. foreach ($data as $key => $value) {
  93. $fields[$key] = $value;
  94. }
  95. }
  96. $headers = array(
  97. 'bt-token:'.$this->accessToken,
  98. 'Content-Type: application/json'
  99. );
  100. // print_r($fields);
  101. // exit;
  102. // Open connection
  103. $ch = curl_init();
  104. // Set the url, number of POST vars, POST data
  105. curl_setopt( $ch, CURLOPT_URL, $this->smsurl );
  106. curl_setopt( $ch, CURLOPT_POST, true );
  107. curl_setopt( $ch, CURLOPT_HTTPHEADER, $headers);
  108. curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
  109. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  110. curl_setopt( $ch, CURLOPT_POSTFIELDS, json_encode($fields));
  111. $info = curl_getinfo($ch);
  112. $result = curl_exec($ch);
  113. if($debug == "Y") {
  114. echo json_encode($fields);
  115. print_r($info);
  116. var_dump($result); //결과 값 출력
  117. print_r(curl_getinfo($ch)); //모든 정보 출력
  118. }
  119. // Execute post
  120. // echo curl_errno($ch); //에러 정보 출력
  121. // echo '<br/><br/>';
  122. // Close connection
  123. curl_close($ch);
  124. $result = json_decode($result, true);
  125. return $result;
  126. }
  127. function sendResult($data){
  128. if(is_array($data)){
  129. foreach ($data as $key => $value) {
  130. $fields[$key] = $value;
  131. }
  132. }
  133. $headers = array(
  134. 'bt-token:'.$this->accessToken,
  135. 'Content-Type: application/json'
  136. );
  137. // print_r($fields);
  138. // exit;
  139. // Open connection
  140. $ch = curl_init();
  141. // Set the url, number of POST vars, POST data
  142. curl_setopt( $ch, CURLOPT_URL, $this->resulturl );
  143. curl_setopt( $ch, CURLOPT_POST, false );
  144. curl_setopt( $ch, CURLOPT_HTTPHEADER, $headers);
  145. curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
  146. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  147. $info = curl_getinfo($ch);
  148. $result = curl_exec($ch);
  149. // echo json_encode($fields);
  150. print_r($info);
  151. print_r($result); //결과 값 출력
  152. // print_r(curl_getinfo($ch)); //모든 정보 출력
  153. // Execute post
  154. // echo curl_errno($ch); //에러 정보 출력
  155. // echo '<br/><br/>';
  156. // Close connection
  157. curl_close($ch);
  158. $result = json_decode($result, true);
  159. return $result;
  160. }
  161. function error($msg){
  162. echo "Android send notification failed with error:";
  163. echo "\t" . $msg;
  164. exit(1);
  165. }
  166. }