payment_bluepay.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?php
  2. define('IN_WEB', true);
  3. define('SKEY', 'Qs2HtcqnMyIqf7Ey');//服务端密钥
  4. $url = 'http://'.$_SERVER['SERVER_NAME'].$_SERVER["REQUEST_URI"];
  5. $sid = (isset($_REQUEST['sid']) == false) ? 1 : $_REQUEST['sid'];
  6. $lid = (isset($_REQUEST['lid']) == false) ? 1 : $_REQUEST['lid'];
  7. if ($sid <= 0) {
  8. die('no sid. in login.');
  9. }
  10. include_once dirname(__FILE__) . "/../com.php";
  11. $ret = encrypt($url);
  12. function encrypt($path){
  13. $path = trim($path);
  14. $start = strpos($path,'?')+1;
  15. $end = strrpos($path,'&') - strlen($path);
  16. //Generate encrypted string by init parameters
  17. $encryptStr = substr($path,$start,$end);
  18. $encryptStr = md5($encryptStr.'Qs2HtcqnMyIqf7Ey');
  19. //Get encrypted string from URL
  20. $encryptParameter = substr($path,-32);
  21. //oo::logs()->debug3($encryptStr, 'payment_bluepay.log');
  22. //Compare the result.
  23. if($encryptStr == $encryptParameter){
  24. return 1;
  25. }else{
  26. return 0;
  27. }
  28. }
  29. if ( $ret == 1 ) {
  30. //获取status, price,t_id, currency
  31. $matches = $param = array();
  32. preg_match_all("#.*&operator=(.*?)&paytype=.*&price=(.*?)&.*&status=(.*?).*&t_id=(.*?).*&currency=(.*?)&interfacetype=(.*?)&.*#iU", $url, $matches);
  33. if( empty($matches) ){
  34. oo::logs()->debug3($url,'payment_bluepay.log');
  35. }
  36. //oo::logs()->debug3(array('m' =>$matches, 'line' => 50),'payment_bluepay.log');
  37. $status = $matches[3][0];
  38. $currency = $matches[5][0];
  39. $param['operator'] = $matches[1][0];//运营商
  40. $param['price'] = $matches[2][0];//价格
  41. $param['orderId'] = $matches[4][0];//订单ID
  42. $param['currency'] = $currency;//计费单位
  43. $param['interfacetype'] = $matches[6][0];//计费类型,sms(短信)/cashcard(充值卡)/bank(银行)/wallet(line)
  44. //oo::logs()->debug3(array('status' =>$status, 'line' => 56),'payment_bluepay.log');
  45. if( $status == 200 && $currency == 'THB' ){//扣费成功,开始发货
  46. $ret = oo::commonOprModel('paymentbluepay')->verifyBluePay($param);
  47. if ($ret) {
  48. return true;
  49. }
  50. }
  51. if( $status == 200 && $currency == 'VND') {//越南支付扣费成功,开始发货
  52. $ret = oo::commonOprModel('paymentvi_bluepay')->verifyBluePay($param);
  53. if ($ret) {
  54. return true;
  55. }
  56. }
  57. }else{
  58. oo::logs()->debug3(array('ret' => $ret, 'url' => $url), 'payment_bluepay.log');
  59. }