Skip to content
23 changes: 23 additions & 0 deletions .github/workflows/php.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: PHP Composer

on: [push]

jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2

- name: Validate composer.json and composer.lock
run: composer validate

- name: Install dependencies
run: composer install --prefer-dist --no-progress --no-suggest

# Add a test script to composer.json, for instance: "test": "vendor/bin/phpunit"
# Docs: https://getcomposer.org/doc/articles/scripts.md

# - name: Run test suite
# run: composer run-script test
81 changes: 81 additions & 0 deletions core/Action/Api.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
<?php
namespace Action;
use Uoke\Controller, HongLing\Order, Services\HomlinOrder, UnionPay\RemitPayment, Services\UnionPay;

class Api extends Controller{

public function __construct() {}

public function hl() {
$do = $this->client->get('do');
if($do == 'create') {
$this->doCreate();
} elseif($do == 'query') {
$this->doQuery();
} elseif($do == 'createTest') {
$this->doTestC();
} elseif($do == 'unionPay') {
$this->doUnionPay();
} elseif($do == 'queryMianLiao') {
$this->mianliao();
}
}

private function mianliao() {
$e = Order::queryFabric($this->client->get('queryFabric'));
$this->rightWithJson($e);
}

private function doUnionPay() {
$apiPost = $this->client->post();
$orderArray = RemitPayment::payTo($apiPost['cardId'], $apiPost['Id'], $apiPost['realName'], $apiPost['money']);
if(isset($orderArray['orderId'])) {
UnionPay::createOrder($orderArray['orderId'], $apiPost['cardId'], $apiPost['Id'], $apiPost['realName'], $apiPost['money']);
if(isset($orderArray['errorMsg'])) {
$this->errorWithJson(array('apiError' => true), $orderArray['errorMsg']);
} else {
$this->rightWithJson(array('orderId' => $orderArray['orderId']), '已经发送去银联接口');
}
} else {
$this->errorWithJson(array('apiError' => true), '答应失败');
}

}

private function doTestC() {
Order::openDebug(Order::DEBUG_TO_LOG);
$apiPost = $this->client->post();
$rInfo = Order::createOrder($apiPost);
if($rInfo['orderPass'] == true) {
HomlinOrder::createOrder($rInfo['orderId'], $apiPost);
$this->rightWithJson(array('orderId' => $rInfo['orderId'], 'jh' => $rInfo), '订单已经保存下单');
} else {
$this->errorWithJson(array('orderId' => null), $rInfo['orderMsg']);
}
}

private function doCreate() {
$apiPost = $this->client->post();
$rInfo = Order::createOrder($apiPost);
if($rInfo['orderPass'] == true) {
HomlinOrder::createOrder($rInfo['orderId'], $apiPost);
HomlinOrder::updateOrderByOrderId($rInfo['orderId'], array('orderPostTime' => strtotime($rInfo['orderJh'])));
$this->rightWithJson(array(
'orderId' => $rInfo['orderId'],
'orderStatus' => 1001,
'orderTime' => strtotime('today'),
'orderPostTime' => strtotime($rInfo['orderJh']),
));
} else {
$this->errorWithJson(array('orderId' => null), $rInfo['orderMsg']);
}
}

private function doQuery() {
$apiPost = $this->client->get();
$orderInfo = Order::queryOrder($apiPost['orderId']);
$this->rightWithJson(array(
'kuaidi' => $orderInfo['kuaidi'],
));
}
}
44 changes: 44 additions & 0 deletions core/Action/Cli.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php
namespace Action;
use morozovsk\websocket\Server;
class Cli {
public function Run() {
global $argv;
$config = array(
'class' => '\Websocket\Chat',
'pid' => MAIN_PATH . '/Data/websocket_chat.pid',
'websocket' => 'tcp://0.0.0.0:89',
'eventDriver' => 'event'
);
if (empty($argv[1]) || !in_array($argv[1], array('start', 'stop', 'restart'))) {
$argv[1] = 'start';
//die("need parameter (start|stop|restart)\r\n");
}
try {
$WebsocketServer = new Server($config);
call_user_func(array($WebsocketServer, $argv[1]));
} catch (\ErrorException $e) {
echo $e->getMessage();
}
}

public function Call() {
global $argv;
$config = array(
'class' => '\Websocket\Call',
'pid' => MAIN_PATH . '/Data/websocket_call.pid',
'websocket' => 'tcp://0.0.0.0:82',
'eventDriver' => 'event'
);
if (empty($argv[1]) || !in_array($argv[1], array('start', 'stop', 'restart'))) {
$argv[1] = 'start';
//die("need parameter (start|stop|restart)\r\n");
}
try {
$WebsocketServer = new Server($config);
call_user_func(array($WebsocketServer, $argv[1]));
} catch (\ErrorException $e) {
echo $e->getMessage();
}
}
}
20 changes: 20 additions & 0 deletions core/Action/Home/BackReceive.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php
namespace Action;
use UnionPay\AcpService;

class Home_BackReceive {

public function Index() {
if (isset ( $_POST ['signature'] )) {
if(AcpService::validate ( $_POST )) {
$orderId = $_POST ['orderId']; //其他字段也可用类似方式获取
$respCode = $_POST ['respCode']; //判断respCode=00或A6即可认为交易成功
echo 'true';
} else {
echo 'error';
}
} else {
echo '签名为空';
}
}
}
89 changes: 89 additions & 0 deletions core/Action/Home/Index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
<?php
namespace Action;
use UnionPay\AcpService;
use UnionPay\SDKConfig;
class Home_Index {

public function Index() {
header ( 'Content-type:text/html;charset=utf-8' );
$accNo = '6226388000000095';
$customerInfo = array(
'certifTp' => '01',
'certifId' => '510265790128303',
'customerNm' => '张三',
);

$params = array(
//以下信息非特殊情况不需要改动
'version' => '5.0.0', //版本号
'encoding' => 'utf-8', //编码方式
'signMethod' => '01', //签名方法
'txnType' => '12', //交易类型
'txnSubType' => '00', //交易子类
'bizType' => '000401', //业务类型
'accessType' => '0', //接入类型
'channelType' => '08', //渠道类型
'currencyCode' => '156', //交易币种,境内商户勿改
'backUrl' => SDKConfig::SDK_BACK_NOTIFY_URL, //后台通知地址
'encryptCertId' => AcpService::getEncryptCertId(), //验签证书序列号

//TODO 以下信息需要填写
'merId' => '777290058110097', //商户代码,请改自己的测试商户号,此处默认取demo演示页面传递的参数
'orderId' => date('YmdHis'), //商户订单号,8-32位数字字母,不能含“-”或“_”,此处默认取demo演示页面传递的参数,可以自行定制规则
'txnTime' => date('YmdHis'), //订单发送时间,格式为YYYYMMDDhhmmss,取北京时间,此处默认取demo演示页面传递的参数
'txnAmt' => 1000, //交易金额,单位分,此处默认取demo演示页面传递的参数
// 'reqReserved' =>'透传信息', //请求方保留域,透传字段,查询、通知、对账文件中均会原样出现,如有需要请启用并修改自己希望透传的数据

// 'accNo' => $accNo, //卡号,旧规范请按此方式填写
// 'customerInfo' => com\unionpay\acp\sdk\AcpService::getCustomerInfo($customerInfo), //持卡人身份信息,旧规范请按此方式填写
'accNo' => AcpService::encryptData($accNo), //卡号,新规范请按此方式填写
'customerInfo' => AcpService::getCustomerInfoWithEncrypt($customerInfo), //持卡人身份信息,新规范请按此方式填写
);

AcpService::sign ( $params ); // 签名
$url = SDKConfig::SDK_BACK_TRANS_URL;

$result_arr = AcpService::post ( $params, $url);
if(count($result_arr)<=0) { //没收到200应答的情况
$this->printResult ( $url, $params, "" );
return;
}

$this->printResult ($url, $params, $result_arr ); //页面打印请求应答数据

if (!AcpService::validate ($result_arr) ){
echo "应答报文验签失败<br>\n";
return;
}

echo "应答报文验签成功<br>\n";
if ($result_arr["respCode"] == "00"){
//交易已受理,等待接收后台通知更新订单状态,如果通知长时间未收到也可发起交易状态查询
//TODO
echo "受理成功。<br>\n";
} else if ($result_arr["respCode"] == "03"
|| $result_arr["respCode"] == "04"
|| $result_arr["respCode"] == "05"
|| $result_arr["respCode"] == "01"
|| $result_arr["respCode"] == "12"
|| $result_arr["respCode"] == "34"
|| $result_arr["respCode"] == "60" ){
//后续需发起交易状态查询交易确定交易状态
//TODO
echo "处理超时,请稍后查询。<br>\n";
} else {
//其他应答码做以失败处理
//TODO
echo "失败:" . $result_arr["respMsg"] . "。<br>\n";
}
}

private function printResult($url, $req, $resp) {
echo "=============<br>\n";
echo "地址:" . $url . "<br>\n";
echo "请求:" . str_replace ( "\n", "\n<br>", htmlentities ( createLinkString ( $req, false, true ) ) ) . "<br>\n";
echo "应答:" . str_replace ( "\n", "\n<br>", htmlentities ( createLinkString ( $resp , false, true )) ) . "<br>\n";
echo "=============<br>\n";
}

}
30 changes: 23 additions & 7 deletions core/Action/Index.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,28 @@
<?php
namespace Action;
use Uoke\Controller, Services\IndexList;
class Index extends Controller{
public function __construct() {}
use Uoke\Controller,
Helper\UploadFile;

class Index extends Controller {

public function __construct() {

}

public function Index() {
$a = json_encode(IndexList::getMyList());
$this->view('a', $a);
$this->display('test');
$this->display('query');
}

public function Test() {
phpinfo();
}

public function TestDo() {
$f = UploadFile::saveAs(function($tempFile) {
var_dump($tempFile['f']);
return $tempFile['f'];
});
var_dump($f);
}
}

}
7 changes: 3 additions & 4 deletions core/Adapter/Db.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ interface Db {
public function table($tableName);
public function getOne();
public function getList();
public function getInsetLastId();
public function getFieldAny($field);
public function getFieldCount($field, $countType);
public function getInsertLastId();
public function getFieldList();
public function getFieldOne();
public function getVersion();
public function insert($data, $return_insert_id = false, $replace = false);
public function insertReplace($data, $affected = false);
Expand All @@ -26,7 +26,6 @@ public function beginTransaction();
public function autocommitTransaction();
public function rollbackTransaction();
public function commitTransaction();

public function handleSqlFunction($sqlTable, $sqlArray);

}
22 changes: 22 additions & 0 deletions core/Config/TraitConfig/HttpCode.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php
namespace Config\TraitConfig;
trait HttpCode {

public function getCode($code) {

$codeText = [
404 => '发送的请求无法找到对应的应用处理',
400 => '发送的请求不符合相关规则,无法处理',
403 => '请求的页面没有获得许可,请返回',
405 => '请求的方式不正确',
500 => '系统错误',
];

return $codeText[$code];
}


public function errorGo($code) {
return true;
}
}
16 changes: 16 additions & 0 deletions core/Config/TraitConfig/Route.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

namespace Config\TraitConfig;

trait Route {

public $routeList = [];
public function routeInit() {

foreach ($this->routeList as $route) {
$this->route->addRoute($route[0], $route[1], $route[2]);
}

}

}
Loading