lzbase.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. <?php
  2. class lzbaseControl
  3. {
  4. private $mMchid;
  5. private $mAdminid;
  6. private $mUseKey;
  7. protected $available;
  8. public function __construct()
  9. {
  10. $mchid = $_POST['usr'];
  11. $mchinfo = Model('merchant')->getMerchantInfo(['mchid' => $mchid]);
  12. if(empty($mchinfo)) {
  13. throw new LzException(self::text_content(-5,0));
  14. }
  15. else {
  16. $this->mAdminid = intval($mchinfo['admin_id']);
  17. }
  18. $minfo = new member_info($this->adminid());
  19. $this->available = $minfo->available_predeposit();
  20. if ($mchinfo['merchant_state'] != 1) {
  21. throw new LzException(self::text_content(-7,$this->available));
  22. }
  23. $ips = unserialize($mchinfo['ip_white_list']);
  24. if(!empty($ips)) {
  25. $addr = $_SERVER['REMOTE_ADDR'];
  26. Log::record("request ip:{$addr}",Log::DEBUG);
  27. if(!in_array($addr,$ips)) {
  28. throw new LzException(self::text_content(-12,$this->available));
  29. }
  30. }
  31. $this->mUseKey = intval($mchinfo['use_key']);
  32. if($this->mUseKey && !$this->verify_md5($mchinfo['secure_key'])) {
  33. throw new LzException(self::text_content(-4,$this->available));
  34. }
  35. $this->mMchid = intval($mchid);
  36. }
  37. public function mchid() : int
  38. {
  39. return $this->mMchid;
  40. }
  41. public function adminid() : int {
  42. return $this->mAdminid;
  43. }
  44. private function verify_md5($key)
  45. {
  46. $input = $_GET;
  47. $sign = $input['sgn'];
  48. $body = $this->sign_body($input);
  49. if($this->mUseKey) {
  50. $body .= $key;
  51. }
  52. return ($sign == strtoupper(md5($body)));
  53. }
  54. private function sign_body($params)
  55. {
  56. $content = $params['usr'] . $params['ord'] . $params['mob'] . $params['amt'] . $params['tim'];
  57. return $content;
  58. }
  59. public static function msg($code)
  60. {
  61. static $msgs = [0 => '订单提交成功',
  62. 2 => '运营商充值账户余额不足',
  63. 4 => '账户余额不足',
  64. 6 => '暂不支持此商品',
  65. 7 => '连接该运营商设备失败',
  66. 8 => '在规定时间内不得重复提交同一号码',
  67. 10 => '该帐号不能在此计算机缴费',
  68. 11 => '流水号重复',
  69. 30 => '面值不符',
  70. 41 => '该地区维护',
  71. 42 => '运营商设备忙',
  72. 43 => '暂不支持该面额的缴费',
  73. 44 => '无该地区缴费权限',
  74. -2 => '命令已发送,请查看交易流水是否有缴费成功(这种情况是服务器在排队等待处理,间隔10-20分钟后查单核实)',
  75. -3 => '数据添加失败',
  76. -4 => '签名错误',
  77. -5 => '没有此代理商',
  78. -6 => '提交失败',
  79. -7 => '无此接口权限',
  80. -8 => '提交日期不是当天日期',
  81. -9 => '参数不对',
  82. -11 => '手机号码位数不符',
  83. -12 => '绑定IP不符',
  84. 1001 => '销售数量请大于0',
  85. 1002 => '该商品库存维护',
  86. 1003 => '该供货商品库存维护'];
  87. if(array_key_exists($code,$msgs)) {
  88. return $msgs[$code];
  89. }
  90. else {
  91. return '';
  92. }
  93. }
  94. public static function text_content($code,$available)
  95. {
  96. $msg = self::msg($code);
  97. $available = ncPriceFormat($available);
  98. $content = "0|{$msg}|{$available}";
  99. return $content;
  100. }
  101. public static function outsuccess($available)
  102. {
  103. echo self::text_content(0,$available);
  104. return true;
  105. }
  106. public static function outerr($code,$available)
  107. {
  108. echo self::text_content($code,$available);
  109. return true;
  110. }
  111. }