|
@@ -5,19 +5,24 @@ class lzbaseControl
|
|
private $mMchid;
|
|
private $mMchid;
|
|
private $mAdminid;
|
|
private $mAdminid;
|
|
private $mUseKey;
|
|
private $mUseKey;
|
|
|
|
+ protected $available;
|
|
|
|
+
|
|
public function __construct()
|
|
public function __construct()
|
|
{
|
|
{
|
|
$mchid = $_POST['usr'];
|
|
$mchid = $_POST['usr'];
|
|
$mchinfo = Model('merchant')->getMerchantInfo(['mchid' => $mchid]);
|
|
$mchinfo = Model('merchant')->getMerchantInfo(['mchid' => $mchid]);
|
|
if(empty($mchinfo)) {
|
|
if(empty($mchinfo)) {
|
|
- throw new Exception("合作方ID:{$mchid}不存在");
|
|
|
|
|
|
+ throw new LzException(self::text_content(-5,0));
|
|
}
|
|
}
|
|
else {
|
|
else {
|
|
$this->mAdminid = intval($mchinfo['admin_id']);
|
|
$this->mAdminid = intval($mchinfo['admin_id']);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ $minfo = new member_info($this->adminid());
|
|
|
|
+ $this->available = $minfo->available_predeposit();
|
|
|
|
+
|
|
if ($mchinfo['merchant_state'] != 1) {
|
|
if ($mchinfo['merchant_state'] != 1) {
|
|
- throw new LzException("机构已被关闭。");
|
|
|
|
|
|
+ throw new LzException(self::text_content(-7,$this->available));
|
|
}
|
|
}
|
|
|
|
|
|
$ips = unserialize($mchinfo['ip_white_list']);
|
|
$ips = unserialize($mchinfo['ip_white_list']);
|
|
@@ -26,13 +31,13 @@ class lzbaseControl
|
|
Log::record("request ip:{$addr}",Log::DEBUG);
|
|
Log::record("request ip:{$addr}",Log::DEBUG);
|
|
|
|
|
|
if(!in_array($addr,$ips)) {
|
|
if(!in_array($addr,$ips)) {
|
|
- throw new Exception("请求地址不在白名单中");
|
|
|
|
|
|
+ throw new LzException(self::text_content(-12,$this->available));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
$this->mUseKey = intval($mchinfo['use_key']);
|
|
$this->mUseKey = intval($mchinfo['use_key']);
|
|
if($this->mUseKey && !$this->verify_md5($mchinfo['secure_key'])) {
|
|
if($this->mUseKey && !$this->verify_md5($mchinfo['secure_key'])) {
|
|
- throw new UnSignException();
|
|
|
|
|
|
+ throw new LzException(self::text_content(-4,$this->available));
|
|
}
|
|
}
|
|
|
|
|
|
$this->mMchid = intval($mchid);
|
|
$this->mMchid = intval($mchid);
|
|
@@ -46,99 +51,80 @@ class lzbaseControl
|
|
return $this->mAdminid;
|
|
return $this->mAdminid;
|
|
}
|
|
}
|
|
|
|
|
|
- private function pubKey($mchid)
|
|
|
|
- {
|
|
|
|
- static $pubs = [];
|
|
|
|
-
|
|
|
|
- if(array_key_exists($mchid,$pubs)) {
|
|
|
|
- return $pubs[$mchid];
|
|
|
|
- }
|
|
|
|
- else {
|
|
|
|
- $pub_key = BASE_DATA_PATH . "/api/merchant/key/{$mchid}_pub.pem";
|
|
|
|
- $key = file_get_contents($pub_key);
|
|
|
|
- $pub = openssl_get_publickey($key);
|
|
|
|
- $pubs[$mchid] = $pub;
|
|
|
|
- return $pub;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
|
|
|
|
private function verify_md5($key)
|
|
private function verify_md5($key)
|
|
{
|
|
{
|
|
$input = $_GET;
|
|
$input = $_GET;
|
|
- $sign = $input['sign'];
|
|
|
|
-
|
|
|
|
- $input['sign'] = null;
|
|
|
|
- $input['from'] = null;
|
|
|
|
|
|
+ $sign = $input['sgn'];
|
|
|
|
|
|
$body = $this->sign_body($input);
|
|
$body = $this->sign_body($input);
|
|
-
|
|
|
|
if($this->mUseKey) {
|
|
if($this->mUseKey) {
|
|
- $body .= "&key={$key}";
|
|
|
|
|
|
+ $body .= $key;
|
|
}
|
|
}
|
|
|
|
|
|
- return ($sign == md5($body));
|
|
|
|
|
|
+ return ($sign == strtoupper(md5($body)));
|
|
}
|
|
}
|
|
|
|
|
|
- private function verify_rsa($mchid)
|
|
|
|
|
|
+ private function sign_body($params)
|
|
{
|
|
{
|
|
- $pub = $this->pubKey($mchid);
|
|
|
|
- if(empty($pub)) {
|
|
|
|
- return false;
|
|
|
|
- }
|
|
|
|
- $input = $_GET;
|
|
|
|
- $sign = $input['sign'];
|
|
|
|
- $input['sign'] = null;
|
|
|
|
- $input['from'] = null;
|
|
|
|
-
|
|
|
|
- $data = $this->sign_body($input);
|
|
|
|
- $res = openssl_verify($data,base64_decode($sign),$pub);
|
|
|
|
- Log::record("openssl_verify res={$res}",Log::DEBUG);
|
|
|
|
-
|
|
|
|
- return ($res == 1);
|
|
|
|
|
|
+ $content = $params['usr'] . $params['ord'] . $params['mob'] . $params['amt'] . $params['tim'];
|
|
|
|
+ return $content;
|
|
}
|
|
}
|
|
|
|
|
|
- protected function check_empty($value)
|
|
|
|
|
|
+ public static function msg($code)
|
|
{
|
|
{
|
|
- if (!isset($value))
|
|
|
|
- return true;
|
|
|
|
- if ($value === null)
|
|
|
|
- return true;
|
|
|
|
- if (trim($value) === "")
|
|
|
|
- return true;
|
|
|
|
-
|
|
|
|
- return false;
|
|
|
|
|
|
+ static $msgs = [0 => '订单提交成功',
|
|
|
|
+ 2 => '运营商充值账户余额不足',
|
|
|
|
+ 4 => '账户余额不足',
|
|
|
|
+ 6 => '暂不支持此商品',
|
|
|
|
+ 7 => '连接该运营商设备失败',
|
|
|
|
+ 8 => '在规定时间内不得重复提交同一号码',
|
|
|
|
+ 10 => '该帐号不能在此计算机缴费',
|
|
|
|
+ 11 => '流水号重复',
|
|
|
|
+ 30 => '面值不符',
|
|
|
|
+ 41 => '该地区维护',
|
|
|
|
+ 42 => '运营商设备忙',
|
|
|
|
+ 43 => '暂不支持该面额的缴费',
|
|
|
|
+ 44 => '无该地区缴费权限',
|
|
|
|
+ -2 => '命令已发送,请查看交易流水是否有缴费成功(这种情况是服务器在排队等待处理,间隔10-20分钟后查单核实)',
|
|
|
|
+ -3 => '数据添加失败',
|
|
|
|
+ -4 => '签名错误',
|
|
|
|
+ -5 => '没有此代理商',
|
|
|
|
+ -6 => '提交失败',
|
|
|
|
+ -7 => '无此接口权限',
|
|
|
|
+ -8 => '提交日期不是当天日期',
|
|
|
|
+ -9 => '参数不对',
|
|
|
|
+ -11 => '手机号码位数不符',
|
|
|
|
+ -12 => '绑定IP不符',
|
|
|
|
+ 1001 => '销售数量请大于0',
|
|
|
|
+ 1002 => '该商品库存维护',
|
|
|
|
+ 1003 => '该供货商品库存维护'];
|
|
|
|
+
|
|
|
|
+ if(array_key_exists($code,$msgs)) {
|
|
|
|
+ return $msgs[$code];
|
|
|
|
+ }
|
|
|
|
+ else {
|
|
|
|
+ return '';
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
- private function sign_body($params)
|
|
|
|
|
|
+ public static function text_content($code,$available)
|
|
{
|
|
{
|
|
- ksort($params);
|
|
|
|
-
|
|
|
|
- $content = "";
|
|
|
|
- $i = 0;
|
|
|
|
- foreach ($params as $k => $v)
|
|
|
|
- {
|
|
|
|
- if (false === $this->check_empty($v) && "@" != substr($v, 0, 1))
|
|
|
|
- {
|
|
|
|
- if ($i == 0) {
|
|
|
|
- $content .= "{$k}" . "=" . urlencode($v);
|
|
|
|
- } else {
|
|
|
|
- $content .= "&" . "{$k}" . "=" . urlencode($v);
|
|
|
|
- }
|
|
|
|
- $i++;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
|
|
+ $msg = self::msg($code);
|
|
|
|
+ $available = ncPriceFormat($available);
|
|
|
|
+ $content = "0|{$msg}|{$available}";
|
|
return $content;
|
|
return $content;
|
|
}
|
|
}
|
|
|
|
|
|
- public static function outsuccess($data)
|
|
|
|
|
|
+ public static function outsuccess($available)
|
|
{
|
|
{
|
|
- joutput_data($data);
|
|
|
|
|
|
+ echo self::text_content(0,$available);
|
|
return true;
|
|
return true;
|
|
}
|
|
}
|
|
- public static function outerr($code, $msg = '')
|
|
|
|
|
|
+
|
|
|
|
+ public static function outerr($code,$available)
|
|
{
|
|
{
|
|
- joutput_error($code, $msg);
|
|
|
|
|
|
+ echo self::text_content($code,$available);
|
|
return true;
|
|
return true;
|
|
}
|
|
}
|
|
}
|
|
}
|