242 lines
7.2 KiB
PHP
242 lines
7.2 KiB
PHP
<?php
|
|
|
|
namespace app\channel\service\system;
|
|
|
|
class Jiyu extends Core
|
|
{
|
|
protected $host = '';
|
|
protected $mid = '';
|
|
protected $token = '';
|
|
protected $api = '';
|
|
//话费直充
|
|
public function dhcz($param){
|
|
$check = array
|
|
(
|
|
'mobile' => 'recharge_account',
|
|
'cash'=>'quantity'
|
|
);
|
|
$this->api='api/buy';
|
|
return $this->submit($param, $check);
|
|
}
|
|
|
|
public function ydcz($param)
|
|
{
|
|
return $this->dhcz($param);
|
|
}
|
|
public function dxcz($param)
|
|
{
|
|
return $this->dhcz($param);
|
|
}
|
|
public function ltcz($param)
|
|
{
|
|
return $this->dhcz($param);
|
|
}
|
|
# 通用卡密购买
|
|
public function cardbuy($param)
|
|
{
|
|
$check = array
|
|
(
|
|
'account' => 'recharge_account',
|
|
'cash'=>'quantity'
|
|
);
|
|
$this->api='api/buy';
|
|
return $this->submit($param, $check);
|
|
}
|
|
public function mhql_cardbuy($param){
|
|
$check = array
|
|
(
|
|
'account' => 'recharge_account',
|
|
'cash'=>'cash'
|
|
);
|
|
$this->api='api/buy';
|
|
return $this->submit($param, $check);
|
|
}
|
|
public function jdhy_cardbuy($param){
|
|
$check = array
|
|
(
|
|
'account' => 'recharge_account',
|
|
'cash'=>'cash'
|
|
);
|
|
$this->api='api/buy';
|
|
return $this->submit($param, $check);
|
|
}
|
|
|
|
# 通知处理 主要返回状态 2是成功 3是失败
|
|
public function notify($data)
|
|
{
|
|
$result = array();
|
|
$result['cash'] = 1;
|
|
$result['status'] = 4;
|
|
if(isset($data['query_status'])){
|
|
if ($data['query_status'] == 200) {
|
|
$result['status'] = 2;
|
|
} else if($data['query_status'] == 500) {
|
|
$result['status'] = 3;
|
|
}else {
|
|
$result['status'] = 4;
|
|
}
|
|
}else{
|
|
if ($data['state'] == 200) {
|
|
$result['status'] = 2;
|
|
} else if($data['state'] == 500) {
|
|
$result['status'] = 3;
|
|
}else {
|
|
$result['status'] = 4;
|
|
}
|
|
}
|
|
if(isset($data['cards'])&&$data['cards']&&is_array($data['cards'])){
|
|
|
|
$result['kami'] = array
|
|
(
|
|
'cardno' => isset($data['cards'][0]['card_no'])?$data['cards'][0]['card_no']:'',
|
|
'cardpwd' => $data['cards'][0]['card_password'],
|
|
'expired' => isset($data['cards'][0]['expired_at'])?$data['cards'][0]['expired_at']:'',
|
|
// 'value' => $array['data']['count_money'],
|
|
);
|
|
}
|
|
if(isset($data['kami'])&&$data['kami']){
|
|
$result['kami']=$data['kami'];
|
|
}
|
|
$result['yes'] = 'ok';
|
|
|
|
$result['data'] = $data;
|
|
|
|
return $result;
|
|
}
|
|
public function query($order){
|
|
$request['customer_id'] = $this->mid;
|
|
$request['order_id'] = $order['merchant_order_id'];
|
|
$request['timestamp'] = time();
|
|
$request['sign'] = $this->_sign($request);
|
|
$url = $this->host . 'api/order';
|
|
$response = $this->curl('post', $url, $request);
|
|
|
|
$log['type'] = 'query_response';
|
|
$log['data'] = $response;
|
|
$log['config'] = $this->data;
|
|
$this->log($log);
|
|
|
|
$array = $this->json_decode($response,true);
|
|
|
|
$result = array();
|
|
$result['status'] = 4;
|
|
if ($array['code']=='ok' ) {
|
|
if($array['state'] ==200){
|
|
$result['query_status'] = 200;
|
|
|
|
$result['status'] = 2;
|
|
}elseif ($array['state'] == 500){
|
|
$result['query_status'] = 500;
|
|
$result['status'] = 3;
|
|
}
|
|
|
|
}
|
|
if(isset($array['data']['cards'])){
|
|
$result['kami']=array(
|
|
'cardno' => isset($array['data']['cards'][0]['card_no'])?$array['data']['cards'][0]['card_no']:'',
|
|
'cardpwd' => $array['data']['cards'][0]['card_password'],
|
|
'expired' => $array['data']['cards'][0]['expired_at'],
|
|
);
|
|
}
|
|
return $result;
|
|
}
|
|
# 数据响应格式处理
|
|
public function response($data)
|
|
{
|
|
$log['type'] = 'response';
|
|
$log['data'] = $data;
|
|
$log['config'] = $this->data;
|
|
$this->log($log);
|
|
|
|
$array = $this->json_decode($data);
|
|
if (!$array) {
|
|
$msg = 'error';
|
|
} elseif (isset($array['code']) && $array['code']=='ok') {
|
|
# 正确
|
|
$msg = 'ok';
|
|
if(isset($array['cards'])){
|
|
$array['kami'] = array
|
|
(
|
|
'cardno' => $array['cards'][0]['card_no'],
|
|
'cardpwd' => $array['cards'][0]['card_password'],
|
|
'expired' => $array['cards'][0]['expired_at'],
|
|
// 'value' => $array['data']['count_money'],
|
|
);
|
|
}
|
|
} else {
|
|
# 错误
|
|
$msg = $array['message'] ?? 'error';
|
|
}
|
|
|
|
return array
|
|
(
|
|
'msg' => $msg,
|
|
'data' => $data,
|
|
'array' => $array,
|
|
);
|
|
}
|
|
|
|
# 查询余额接口
|
|
public function account($day)
|
|
{
|
|
$request['customer_id'] = $this->mid;
|
|
$request['timestamp']=time();
|
|
$request['sign'] = $this->_sign($request);
|
|
$url = $this->host . 'api/customer';
|
|
$response = $this->curl('post', $url, $request);
|
|
$response = $this->response($response);
|
|
|
|
$datas = $response['array']['data'];
|
|
if(is_array($datas) && isset($datas['balance']) && $datas['balance'] ){
|
|
$datas['account'] = $datas['balance'];
|
|
}
|
|
|
|
return $datas;
|
|
}
|
|
|
|
|
|
# 提交数据
|
|
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['customer_id']=$this->mid;
|
|
if(!isset($request['quantity'])){
|
|
$request['quantity']=$param['cash'] ?? 1;
|
|
}
|
|
|
|
$request['notify_url']=$this->getNotify($param['order'], 1);
|
|
$request['outer_order_id']=$param['order'];
|
|
$request['product_id']=$this->getGid($param['cash']);
|
|
$request['timestamp']=time();
|
|
// unset($request['cash']);
|
|
$request['sign'] = $this->_sign($request);
|
|
$url = $this->host . $this->api;
|
|
|
|
$response = $this->curl('post', $url, $request);
|
|
$response = $this->response($response);
|
|
$channel_order_id = '';
|
|
|
|
if($response['array']['code']=='ok' && isset($response['array']['data']['order_id']) && $response['array']['data']['order_id']){
|
|
$channel_order_id = $response['array']['data']['order_id'];
|
|
}
|
|
|
|
$this->create($param['order'], $channel_order_id, $param['merchant_order'], $param['cash'], $url, $request, $response, 1, $param['account']);
|
|
return $response['msg'];
|
|
}
|
|
|
|
private function _sign($request)
|
|
{
|
|
// unset($request['cash']);
|
|
ksort($request);
|
|
$str=$this->token;
|
|
foreach($request as $k=>$v){
|
|
$str.=$k.$v;
|
|
}
|
|
$str=strtolower(md5($str));
|
|
return $str;
|
|
}
|
|
} |