REAPI/app/openapi/controller/kamiquery/Shengxiakami.php
2024-09-29 15:43:18 +08:00

610 lines
18 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
//
//namespace app\openapi\controller\kamiquery;
//
//use app\gateway\service\CurlService;
//use app\gateway\service\RedisService as redisObj;
//use app\merchant\service\MerchantService;
//use app\merchant\service\OrderHistoryService;
//use app\merchant\service\OrderService;
//use app\order\service\Kami91OrderService;
//use think\admin\Controller;
//use app\core\Service as CoreService;
//use think\facade\Log;
//
//class Shengxiakami extends Controller
//{
//
// # 是否检测数据
//// protected bool $check = false;
// protected $merchant_id;
//
// # code码定义
// protected $code = array
// (
// # 成功
// 1 => 'ok',
// # 小于0为失败
// -1 => 'appid为空',
// -2 => '产品错误',
// -3 => 'appid无效',
// -4 => '余额不足或者没有传入价格',
//
// -5 => 'signature不能为空',
// -6 => 'nonce不能为空',
// -7 => 'time不能为空',
// -8 => 'signature已失效',
// -9 => 'signature验证失败',
//
// -100 => '请求错误',
// -101 => '订单不存在',
// -102 => '订单号重复',
//
// -103 => '正在处理中',
//
// -1000 => '系统维护中',
//
// );
//
// protected $token = '31HHu6R4';
// protected $deskey = 'V79x42C7a45zXMn6v85b44r2';
//
//
//
// #签名
//
// public function _Sign($request, $param)
// {
// $signature_string = '';
// foreach ($param as $k => $v) {
//
// $signature_string .= $v . '=' . $request[$v] . '&';
//
// }
//
// $signature_string = substr($signature_string, 0, -1);
//
// $signature_string .= '|||'.md5($this->token);
//// var_dump($signature_string);die;
//// $signature_string = iconv("UTF-8", "gbk", $signature_string);
//
// return md5($signature_string);
//
// }
//
// #3des解密
// public function decrypt_3des($encrypted_string){
//
// $cipher = "des-ede3"; // 3des-ebc 使用的是des-ede3算法
// $mode = "ebc"; // 工作模式为ebc
//
// $iv = ""; // EBC模式不需要IV留空即可
//// $encrypted_string = "bf1c26db1ed2e0d242425e787f4e38e85c8b44c3a7384b582229c823ae4be452b69e16950a33a6b5da0c02395570524fdbc38260ff951280"; // 替换为你的加密字符串
//
// return openssl_decrypt(hex2bin($encrypted_string), $cipher, $this->deskey, $options=OPENSSL_RAW_DATA, $iv); // 输出解密后的字符串
// }
// # 查询接口 一般用于查询数据,同步执行
//
//
//
//
//
// public function query()
// {
//// ret_code=0&ret_msg=提卡成功&shop_id=61&bill_id=2064719280539202563&mm_bill_no=F24022323441841026&purchase_amt=50&card_no_data=bf1c26db1ed2e0d242425e787f4e38e85c8b44c3a7384b582229c823ae4be452b69e16950a33a6b5da0c02395570524fdbc38260ff951280&sign=8acf89a797a9e90235b4c29cfe9b312e
//
//
// $orderService = OrderService::instance();
// $where = [
// 'status' => '4' ,
// 'product_key' => ['like','%cardbuy%'] ,
// 'cid' => 5
// ];
// $orderlist = $orderService->db()->where($where)->order('id asc')->select()->toArray();
// foreach($orderlist as $key=>$v) {
//
// $url = 'http://58.220.211.41:12009/api/UCardFetchQuery';
// $query = [
// 'shop_id' => '61',
// 'bill_id' => $v['merchant_order_id'],
// 'time_stamp' => date('YmdHis'),
// ];
// $query['sign'] = $this->_Sign($query, array('shop_id', 'bill_id', 'time_stamp'));
// $msg = http_get($url, $query);
// $pairs = explode('&', $msg);
// $array = [];
// foreach ($pairs as $pair) {
// // 分割键和值
// list($key, $value) = explode('=', $pair);
// // 解码键和值
// $array[urldecode($key)] = urldecode($value);
// }
//
// if (!$array) {
// $this->log($msg);
// }
// if (isset($array['ret_code']) && $array['ret_code'] == '0') {
// $kami = $this->decrypt_3des($array['card_no_data']);
// $kami = explode(',', $kami);
// $kamidata = [
// 'cardno' => $kami[0],
// 'cardpwd' => $kami[1],
// 'expired' => $kami[2],
//
// ];
//
// $this->upOrderResponse($kamidata,$v['merchant_order_id'],$v['response']);
//
// $log['type'] = 'notify';
// $log['request'] = $input;
// $this->log($log);
// if(isset($input[$key]) && $input[$key]) {
// $order_id = $input[$key];
// if ($order_id) {
// if (strstr($order_id, '-')) {
// $temp = explode('-', $order_id);
// $order_id = $temp[0];
// }
// $gatewaycore = new \app\gateway\controller\api\Core($this->app);
// $gatewaycore->notify($order_id, $log['request']);
// }
// }
//
// }
//
//
// }
// }
//
// public function upOrderResponse($kami,$merchant_order_id,$orderResponse)
// {
// $orderService = OrderService::instance();
//
// $response = json_decode($orderResponse,true);
// $response['kami'] = $kami;
// $data = ['response' => json_encode($response)];
//
// $orderService->db()->where(array('merchant_order_id' => $merchant_order_id))->update($data);
// }
//
// protected function getOrder($order_id, $merchant_order_id = false ,$mid = false)
// {
// $orderService = OrderService::instance();
// $order = $orderService->get($order_id, $merchant_order_id ,$mid);
// if (!$order) {
// $orderHistoryService = OrderHistoryService::instance();
// $order = $orderHistoryService->get($order_id, $merchant_order_id ,$mid);
// }
// return $order;
// }
//
// public function submit()
// {
// #注意修改id
//// $this->mid = '2';
//
// $input = input();
//
// $this->log($input,'submit');
//
//
// $data = [];
//
// if (empty($input)) {
// $this->no(-100);
// }
//
// if (empty($input['appid'])) {
// $this->no(-1);
// }
//
// if (empty($input['order'])) {
// $this->no(-100);
// }
//
// $order = '';
// $merchant_order = $input['order'];
//
//
//
//
// if (isset($input['proid'])) {
// $input['proid'] = $this->mapping($input['proid'] );
// # 根据产品id 获取信息
// $pinfo = \app\channel\service\ProductBaseService::instance()->getOne($input['proid']);
// if (!$pinfo) {
// $this->no(-2);
// }
//
//
// $data['product_key'] = $pinfo['key'];
// $data['cash'] = $pinfo['value'] ;
// $pid = \app\channel\service\ProductBaseService::instance()->getProductId($pinfo['service_id']);
//
// $data['pid'] = $pid['id'];
// } else {
// $this->no(-2);
// }
//
//
// $data['status'] = '1';
// $data['param'] = json_encode($input);
//
//
//
//
//
//
//
//// if ($data['request'] && $data['status'] == '-7') {
//// $data['request'] = json_decode($data['request'], true);
////// \app\gateway\controller\api\Task::run($data['request'], true);
////
//// }
//
// $getMerchantInfo = MerchantService::instance()->get($input['appid']);
// $data['mid'] = $getMerchantInfo['id'];
// $orderdata = $this->getOrder($order, $merchant_order ,$getMerchantInfo['id']);
//
// if(!$orderdata){
//
// }else{
// $data['status'] = '4';
// $data['order_id'] = $orderdata['order_id'];
// }
//
// $where = [
// 'mid' => $data['mid'],
// 'merchant_order_id' => $merchant_order
// ];
// $data['merchant_order_id'] = $merchant_order;
// $data['notifyurl'] = $input['notify'];
//
// $result = Kami91OrderService::instance()->up($where,$data);
//
// if(!is_numeric($result)){
// $this->no(-1000);
// }
//// var_dump($orderdata);die;
//
//// if(isset($orderdata['status']) && $orderdata['status'] == '7'){
//// $this->huidiao($orderdata['order_id']);
//// }
// $this->yes('ok');
//
// }
//
// public function mapping($proid)
// {
// if($proid == '5438110079611'){
// return '10074';
// }else{
// return $proid;
// }
// }
//
// public function queryFaka($merchant_order){
// $url='https://s.52jisu.com/open/intf/SendStatus.jsp';
//
// $param = [
// 'tid'=>$merchant_order,
// 'sellerNick'=>'宝斓网游专营店'
// ];
//
//
// $response = $this->send_post( $url, $param, 'POST');
//
// $msg = json_decode($response,true);
//
// if($msg['code'] == '1'){
// return 'ok';
// }else{
// return 'no';
// }
//
//
//
//
//
// }
//
// /**
// * @return string
// */
//// public function queryFaka1()
//// {
////
//// $url='https://s.52jisu.com/open/intf/SendStatus.jsp';
////
//// $param = [
//// 'tid'=>input('orderid'),
//// 'sellerNick'=>'宝斓网游专营店'
//// ];
////
////
//// $response = $this->send_post( $url, $param, 'POST');
//// var_dump($response);die;
//// }
//
// public function uphuidiao($order_id)
// {
//// var_dump(123);die;
// $order = $this->getOrder($order_id);
//
// if(isset($order['channel_callback_msg'])){
//
// $msg = json_decode($order['channel_callback_msg'],true);
// if(isset($msg['kami'])){
// return 'ok';
//// OrderService::instance()->upStatus($order_id);
//
// }else{
// return 'error';
// }
// }else{
//
// $response = json_decode($order['response'],true);
////
// if(isset($response['kami'])){
//// var_dump($response['kami']);die;
// $kami = [
// 'cardno' =>$response['kami']['cardno'],
// 'cardpwd' =>$response['kami']['cardpwd'],
// 'expire_time' =>$response['kami']['expired'],
// ];
//
// $where = [
// 'order_id' => $order_id
// ];
//
// $result = Kami91OrderService::instance()->up($where,$kami);
//// OrderService::instance()->upChannelMsg($order_id,'2',['kami' => $response['kami'],'s_nubmer'=>$response['kami']['cardno']]);
//
// }else{
// return 'error';
// }
// }
//
// return 'ok';
//
//
//
//
// }
//
//
// public function huidiao($order_id)
// {
//// var_dump(123);die;
// $order = $this->getOrder($order_id);
//
// if(isset($order['channel_callback_msg'])){
//
// $msg = json_decode($order['channel_callback_msg'],true);
// if(isset($msg['kami'])){
// OrderService::instance()->upStatus($order_id);
//
// }else{
// return 'error';
// }
// }else{
//
// $response = json_decode($order['response'],true);
////
// if(isset($response['kami'])){
//// var_dump($response['kami']);die;
// $kami = [
// 'cardno' =>$response['kami']['cardno'],
// 'cardpwd' =>$response['kami']['cardpwd'],
// 'expire_time' =>$response['kami']['expired'],
// ];
//
// $where = [
// 'order_id' => $order_id
// ];
//
// $result = Kami91OrderService::instance()->up($where,$kami);
// OrderService::instance()->upChannelMsg($order_id,'2',['kami' => $response['kami'],'s_nubmer'=>$response['kami']['cardno']]);
//
// }else{
// return 'error';
// }
// }
// if ( $order['merchant_callback_error'] != 1) {
//// var_dump(123);die;
// //$update['order'] = $order;
// $update = [];
// $update['status'] = $order['status'];
//
// $update['account'] = $order['account'];
// $update['cash'] = $order['cash'];
// $update['merchant_order_id'] = $order['merchant_order_id'];
// $update['order_id'] = $order_id;
// $update['notify_num'] = $order['merchant_callback_num'];
// $order['param'] = json_decode($order['param'],true);
//
// if ($order['param'] && isset($order['param']['notify']) && $order['param']['notify']) {
// $update['notify'] = $order['param']['notify'];
// }
//
// # 商户后续操作
//
// if (isset($order['error_account_oper']) && $order['error_account_oper'] == 1) {
// # 需要进行扣费
// MerchantService::instance()->up($order['id'], $order['mid'], $order['pid'], $order['product_key'], $update);
// } else {
// # 直接发送
// MerchantService::instance()->notify($order['id'], $order['mid'], $order['pid'], $order['product_key'], $update);
// }
//
// }
// return 'ok';
//
//
//
//
// }
//
//
//
// # 提交接口 一般用于提交数据,异步执行
// public function dc_charge(): void
// {
// $this->submit();
// }
//// protected function getMerchant(): void
//// {
//// $this->merchant = MerchantService::instance()->get('PT_'.$this->agentId);
//// $this->mid = $this->merchant['id'];
////
////// $this->agentId = $this->merchant['agentId'];
////
//// $this->agentkey = $this->merchant['agentkey'];
////
//// $this->callnotify = $this->merchant['notify_url'];
////// $this->signkey = $this->merchant['other_key'];
////
////
//// }
//
//
//
// protected function curl($method, $url, $param = array(), $json = false, $header = false):mixed
// {
// if ($param) {
// $log['type'] = 'request';
// $log['url'] = $url;
// $log['param'] = $param;
// $this->log($log);
// }
//
// $curl = CurlService::getInstance($url, $param, $method, $json, $header);
// $curl->setTimeOut(3600);
// return $curl->result();
// }
//
// protected static function log($data, $type = 'request'):void
// {
// \dever\Log::write('kami91', $type, $data);
//// \dever\Log::write('jingdong', $type, $data);
// }
//
// public function kaminotify( $order_id ,$status)
// {
//
// $kami91Service = Kami91OrderService::instance();
// $getkami91info = $kami91Service->getOrder(1, $order_id);
// $url = $getkami91info['notifyurl'];
// $param = array();
// $param['status'] = $status;
// if ($status == 2 ){
// if($getkami91info['status'] == '6'){
//
// $check = $this->queryFaka($getkami91info['merchant_order_id']);
// if($check == 'ok'){
// $msg = 'success';
//// $datas = ['status'=> '2'] ;
// $kami91Service->upStatus($order_id, 2 ,$msg);
//
// return 'ok';
// }else{
// $this->log($check,'errormsg');#写入到日志里
// return 'no';
// }
// }elseif ($getkami91info['status'] == '2'){
// return 'ok';
// }else{
// return 'no';
// }
//
//
// }
// return 'ok';
// if($status == '3'){
// return 'ok';
// }
//
//
//
//
//
//
////// var_dump($param);die;
////// $msg = http_post( $url, $param);
////
////// $msg = $this->send_post( $url, $param, 'POST');
//// $msg = 'success';
////// var_dump($msg);die;
//// $this->log($msg,'msg');#写入到日志里
////
////
//// if($msg != 'success'){
//// $this->log($msg,'errormsg');#写入到日志里
//// $callbalck_status = '3';
//// }else{
//// $callbalck_status = '2';
//// }
////
////
//// if ($callbalck_status == 3){
//// die;
//// }
////
////
////
////
//// return $upstatus;
// }
//
// public function send_post($notify_url, $post_data, $type): mixed
// {
//
// $postdate = http_build_query($post_data);
//
// $options = array(
// 'http' => array(
// 'method' => $type,
// 'header' => 'Content-type:application/x-www-form-urlencoded',
// 'content' => $postdate,
// 'timeout' => 15 * 60 // 超时时间(单位:s
// )
// );
// $context = stream_context_create($options);
// return file_get_contents($notify_url, false, $context);
// }
//
// /**
// * 返回失败的消息
// * @param mixed $info
// * @param string $data
// * @param integer $code
// */
// protected function no($code = 0, $info = '', $data = '{-null-}')
// {
// $msg = $this->code[$code] ?? 'error';
// if ($info) {
// $msg .= ':' . $info;
// }
// $data = '{-null-}';
// $this->error($msg, $data, $code);
// }
//
// /**
// * 返回成功的消息
// * @param mixed $info
// * @param string $data
// * @param integer $code
// */
// protected function yes($data = '{-null-}', $info = 'ok', $code = 1)
// {
// if (is_string($data) && $data != 'ok' && $data != 'success') {
// if ($data == '订单号重复') {
// return $this->no(-102);
// }
// return $this->no(-100, $data);
// }
// $this->success($info, $data, $code);
// }
//
//
//}