2024-09-29 15:43:18 +08:00

356 lines
9.8 KiB
PHP

<?php
namespace app\channel\service\system;
/**
* 话费服务
* Class Common
* @package app\channel\service
*/
class Yunling extends Core
{
# 这几个可以后台设置
protected $host = 'host';
protected $mid = 'mid';
protected $token = 'token';
protected $api = 'api';
# 通用的充值
public function common($param)
{
$check = array
(
'account' => 'account',
'cash' => 'price',
'areaid' => 'areaid',
'serverid' => 'serverid',
);
$this->api = 'gameonlinepay.do';
$this->paytype = 'douyin';
$param['areaid'] = -1;
$param['serverid'] = -1;;
$this->sign = array('userid', 'productid', 'num', 'areaid', 'serverid', 'account', 'spordertime', 'sporderid');
return $this->submit($param, $check);
}
# 抖音
public function dycz($param)
{
$check = array
(
'account' => 'account',
'cash' => 'price',
'areaid' => 'areaid',
'serverid' => 'serverid',
);
$this->api = 'gameonlinepay.do';
$this->paytype = 'douyin';
$param['areaid'] = -1;
$param['serverid'] = -1;;
$this->sign = array('userid', 'productid', 'num', 'areaid', 'serverid', 'account', 'spordertime', 'sporderid');
return $this->submit($param, $check);
}
# 电费
public function dfcz($param)
{
$check = array
(
'account' => 'account',
);
if (!isset($param['area'])) {
return 'error';
}
if (!isset($param['username'])) {
return 'error';
}
$param['account'] = array
(
'product_type' => 3,
'userid' => $param['account'],
'username' => $param['username'],
'type' => 1,
'area' => $param['area'],
);
$param['account'] = json_encode($param['account']);
$this->api = 'gameonlinepay.do';
$this->paytype = 'dianfei';
$this->sign = array('userid', 'productid', 'num', 'account', 'spordertime', 'sporderid');
return $this->submit($param, $check);
}
# 电话充值
public function dhcz($param)
{
$check = array
(
'mobile' => 'mobile',
'cash' => 'price',
'paytype' => 'paytype',
);
$this->api = 'onlinepay.do';
if (isset($param['isp']) && $param['isp']) {
$isp = $param['isp'];
} else {
$isp = $this->isp($param['mobile']);
}
$paytype = '';
if ($isp == 1) {
$paytype = 'yd';
}
if ($isp == 2) {
$paytype = 'lt';
}
if ($isp == 3) {
$paytype = 'dx';
}
$param['paytype'] = $paytype;
$this->paytype = $paytype;
$this->sign = array('userid', 'productid', 'price', 'num', 'mobile', 'spordertime', 'sporderid');
return $this->submit($param, $check);
}
# 电话充值
public function zshcz($param)
{
$check = array
(
'card' => 'mobile',
'cash' => 'price',
);
$this->api = 'onlinepay.do';
$this->paytype = 'zshcz';
$this->sign = array('userid', 'productid', 'price', 'num', 'mobile', 'spordertime', 'sporderid');
return $this->submit($param, $check);
}
# 通知处理 主要返回状态 2是成功 3是失败
public function notify($data)
{
$request = $data;
unset($request['sign']);
unset($request['s_order']);
$sign = strtoupper($this->_sign($request, array('userid', 'orderid', 'sporderid', 'merchantsubmittime', 'resultno')));
if ($sign != $data['sign']) {
return false;
}
$result = array();
$result['cash'] = 1;
if ($data['resultno'] == 1) {
$result['status'] = 2;
} elseif ($data['resultno'] == 9) {
$result['status'] = 3;
} else {
$result['status'] = 4;
}
if (isset($data['remark1']) && $data['remark1']) {
# 流水号
$data['s_nubmer'] = $result['s_nubmer'] = $data['remark1'];
}
$result['yes'] = 'OK';
$result['data'] = $data;
return $result;
}
# 数据响应格式处理
public function response($data)
{
$log['type'] = 'response';
$log['data'] = $data;
$log['config'] = $this->data;
$this->log($log);
$data = str_replace('gb2312', 'UTF-8', $data);
$data = mb_convert_encoding($data, 'GBK', 'UTF-8');
$array = (array) simplexml_load_string($data);
if (!$array) {
$msg = 'error';
} elseif (isset($array['resultno']) && $array['resultno'] == '0') {
# 正确
$msg = 'ok';
} else {
# 错误
$msg = $array['resultno'];
}
return array
(
'msg' => $msg,
'data' => $array,
'array' => $array,
);
}
# 查询接口
public function query($param)
{
}
# 提交数据
private function submit($param, $check)
{
$param = $this->param($param, $check);
if (is_string($param) || (is_array($param) && $param['status'] == 1)) {
return $param;
}
$request = $param['detail'];
$request['num'] = 1;
$request['productid'] = '';
$request['userid'] = $this->mid;
$request['sporderid'] = $param['order'];
$request['spordertime'] = date('YmdHis');
$request['back_url'] = $this->getNotify($param['order'], 1);
$request['productid'] = $this->getCode($param['cash']);
if (isset($request['areaid']) && $request['areaid'] == -1) {
$request['areaid'] = '';
}
if (isset($request['serverid']) && $request['serverid'] == -1) {
$request['serverid'] = '';
}
$request['sign'] = $this->_sign($request, $this->sign);
$url = $this->host . $this->api;
$response = $this->curl('get', $url, $request);
$response = $this->response($response);
$channel_order_id = '';
if (isset($response['array']['orderid'])) {
$channel_order_id = $response['array']['orderid'];
}
$this->create($param['order'], $channel_order_id, $param['merchant_order'], $param['cash'], $url, $request, $response, 1, $param['account']);
return $response['msg'];
}
private function getCode($cash)
{
if ($this->paytype == 'yd') {
if ($cash == 30) {
return 101687;
} elseif ($cash == 50) {
return 101688;
} elseif ($cash == 100) {
return 101689;
} elseif ($cash == 200) {
return 101690;
}
} elseif ($this->paytype == 'lt') {
if ($cash == 30) {
return 101705;
} elseif ($cash == 50) {
return 101706;
} elseif ($cash == 100) {
return 101707;
} elseif ($cash == 200) {
return 101708;
}
} elseif ($this->paytype == 'dx') {
if ($cash == 30) {
return 101723;
} elseif ($cash == 50) {
return 101724;
} elseif ($cash == 100) {
return 101725;
} elseif ($cash == 200) {
return 101726;
}
} elseif ($this->paytype == 'douyin') {
if ($cash == 50) {
return 30000005213;
} elseif ($cash == 100) {
return 30000005214;
} elseif ($cash == 200) {
return 30000005215;
} elseif ($cash == 300) {
return 30000005216;
} elseif ($cash == 500) {
return 30000005217;
}
} elseif ($this->paytype == 'zshcz') {
if ($cash == 100) {
return 30000005208;
} elseif ($cash == 200) {
return 30000005209;
} elseif ($cash == 500) {
return 30000005210;
} elseif ($cash == 1000) {
return 30000005211;
}
} elseif ($this->paytype == 'dianfei') {
if ($cash == 100) {
return 30000005203;
} elseif ($cash == 200) {
return 30000005204;
} elseif ($cash == 300) {
return 30000005205;
} elseif ($cash == 500) {
return 30000005206;
} elseif ($cash == 1000) {
return 30000005207;
}
}
return 11;
}
private function _sign($request, $param)
{
//ksort($request);
$signature_string = '';
foreach ($param as $k => $v) {
if (isset($request[$v])) {
$signature_string .= $v . '=' . $request[$v] . '&';
}
}
$signature_string .= 'key=' . $this->token;
return strtoupper(md5($signature_string));
}
public function isp($mobile)
{
//return $this->getphonetype($mobile);
$url = 'http://cx.shouji.360.cn/phonearea.php?number=' . $mobile;
$data = $this->curl('get', $url);
if ($data) {
$data = json_decode($data, true);
if ($data && isset($data['data']['sp'])) {
$sp = $data['data']['sp'];
if ($sp == '移动') {
return 1;
} elseif ($sp == '联通') {
return 2;
} elseif ($sp == '电信') {
return 3;
}
}
}
return 4;
}
}