Commit 488ab881 authored by wanjilong's avatar wanjilong

add: 增加mon打点

parent 048a425a
...@@ -19,7 +19,7 @@ class Bootstrap extends Yaf\Bootstrap_Abstract{ ...@@ -19,7 +19,7 @@ class Bootstrap extends Yaf\Bootstrap_Abstract{
*/ */
public function _initConfig() { public function _initConfig() {
$globalConfig = Yaf\Application::app()->getConfig(); $globalConfig = Yaf\Application::app()->getConfig();
Yaf\Registry::set('cliConfig', $globalConfig); Yaf\Registry::set('config', $globalConfig);
} }
......
<?php
namespace Helpers;
use Api\PhpUtils\Log\FileLog;
use Helpers\Tracer;
use Api\PhpUtils\Http\HttpUtil;
use Api\PhpUtils\Http\Request;
use App\Exception\BaseException;
/**
* DingTalk 获取接口
*/
class DingTalk {
public static function send($title, $text = '') {
$tokens = \Yaf\Application::app()->getConfig()->get('dingTalk.tokens');
$keys = \Yaf\Application::app()->getConfig()->get('dingTalk.keys');
$len = count($tokens);
$idx = rand(1, 9999) % $len;
$hook_url = "https://oapi.dingtalk.com/robot/send?access_token=" . $tokens[$idx];
$t = time() * 1000;
$ts = $t."\n".$keys[$idx];
$sig = hash_hmac('sha256', $ts, $keys[$idx], true);
$sig = base64_encode($sig);
$sig = urlencode($sig);
$text = '#### **' . $title . "** \n -------- \n "
. 'time: ' . date("Y-m-d H:i:s"). " \n -------- \n "
. 'traceId: ' . Tracer::getTraceId() . " \n -------- \n "
. $text;
$data_string = json_encode([
'msgtype' => 'markdown',
'markdown' => [
'title'=>$title ,
'text' => $text]
]);
$url = $hook_url.'&timestamp='.$t.'&sign='.$sig;
$result = self::post($url, $data_string, ['Content-Type: application/json']);
return array('code' => 0, 'msg' => 'success', 'result' => $result );
}
public static function post($url, $params, $headers = [], $timeout_ms = 1000) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
if ($headers) {
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
}
curl_setopt($ch, CURLOPT_FAILONERROR, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TCP_NODELAY, true);
curl_setopt($ch, CURLOPT_NOSIGNAL, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_BUFFERSIZE, 10240);
curl_setopt($ch, CURLOPT_TIMEOUT_MS, $timeout_ms);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT_MS, $timeout_ms);
//curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
$res = curl_exec($ch);
$curl_errno = curl_errno($ch);
$curl_error = curl_error($ch);
echo $res;
curl_close($ch);
if (empty($curl_errno)) {
return json_decode($res, true);
} else {
return ["code" => $curl_errno, "status" => "failed", "reason" => $curl_error];
}
}
}
\ No newline at end of file
<?php
use App\Base\Base;
use App\Models\order\mysql\PayOrderItem;
use App\Services\pay\PayService;
use App\Services\refund\RefundService;
use App\Models\order\mysql\CallbackLog;
use Helpers\DingTalk;
class TccController extends Base
{
/**
* 创建支付订单,返回前端ping++的支付信息
*/
public function tryAction()
{
if(!empty($this->params['sleep'])) {
sleep($this->params['sleep']);
}
if(!empty($this->params['throw'])) {
throw new \Exception('test for Exception.', '3001');
}
if(!empty($this->params['lock'])) {
//todo make a lock for mysql
}
$this->success(['result'=>[]]);
}
public function confirmAction() {
if(!empty($this->params['sleep'])) {
sleep($this->params['sleep']);
}
if(!empty($this->params['throw'])) {
throw new \Exception('test for Exception.', '3001');
}
if(!empty($this->params['lock'])) {
//todo make a lock for mysql
}
$this->success(['result'=>[]]);
}
public function cancelAction() {
if(!empty($this->params['sleep'])) {
sleep($this->params['sleep']);
}
if(!empty($this->params['throw'])) {
throw new \Exception('test for Exception.', '3001');
}
if(!empty($this->params['lock'])) {
//todo make a lock for mysql
}
$this->success(['result'=>[]]);
}
public function traceAction() {
\Helpers\Tracer::info('traceId', '');
}
public function pdoAction() {
$dsn = 'mysql:dbname=testdb;host=127.0.0.1';
$user = 'dbuser';
$password = 'dbpass';
$user = config('mysql', 'pay.username');
$password = config('mysql', 'pay.password');
$host = config('mysql', 'pay.write.host');
$db = config('mysql', 'pay.database_name');
$dsn = 'mysql:dbname=' . $db . ';host=' . $host;
$dbh = new PDO($dsn, $user, $password);
sleep(15);
$sth = $dbh->prepare('SELECT * FROM pay_order WHERE user_id = ? limit 1');
var_dump($sth, '----');
$sth->execute([510226436112]);
$one = $sth->fetchAll();
$sth->execute([510230120298]);
$two = $sth->fetchAll();
$this->success(['one'=>$one, 'two'=>$two]);
}
}
...@@ -8,6 +8,7 @@ use Pingpp\Order; ...@@ -8,6 +8,7 @@ use Pingpp\Order;
use Pingpp\Pingpp; use Pingpp\Pingpp;
use Pingpp\OrderRefund; use Pingpp\OrderRefund;
use Api\PhpUtils\Common\IP; use Api\PhpUtils\Common\IP;
use Api\PhpUtils\Mon\MonUtil;
class PingxxService class PingxxService
...@@ -42,10 +43,8 @@ class PingxxService ...@@ -42,10 +43,8 @@ class PingxxService
public function sendRefund($refundData) { public function sendRefund($refundData) {
try { try {
FileLog::info('ping++:' . '退款订单发起', json_encode($refundData, JSON_UNESCAPED_UNICODE));
$royalty_users = []; $royalty_users = [];
$start = microtime(true);
$ret = OrderRefund::create( $ret = OrderRefund::create(
$refundData['id'], $refundData['id'],
[ [
...@@ -56,24 +55,34 @@ class PingxxService ...@@ -56,24 +55,34 @@ class PingxxService
'refund_mode' => 'to_source', //退款模式。原路退回:to_source,退至余额:to_balance。默认为原路返回。 'refund_mode' => 'to_source', //退款模式。原路退回:to_source,退至余额:to_balance。默认为原路返回。
] ]
); );
FileLog::info('ping++:' . '退款订单返回', json_encode(['res'=>$ret], JSON_UNESCAPED_UNICODE)); //Mon 日志监控增加
$end = microtime(true); //计算结束时间
$total_time = round(($end - $start),4) * 1000; //计算耗时
$url = 'pingxx/v1/refund/create';
MonUtil::proxyMon($url, '200', 'bp-pay', $total_time);
FileLog::info('pingxx-sendRefund:' . '退款订单返回', json_encode(['req'=>$refundData, 'res'=>$ret], JSON_UNESCAPED_UNICODE));
$response = json_decode($ret, true); $response = json_decode($ret, true);
return $response;
} catch (\Pingpp\Error\Base $e) { } catch (\Pingpp\Error\Base $e) {
// 捕获报错信息 // 捕获报错信息
if ($e->getHttpStatus() != null) { if ($e->getHttpStatus() != null) {
$response = json_decode($e->getHttpBody(), true);
return json_decode($e->getHttpBody(), true);
} else { } else {
return [ $response = [
'error'=>['message'=>$e->getMessage()], 'error'=>['message'=>$e->getMessage()],
'type'=>'http error', 'type'=>'http error',
]; ];
} }
FileLog::error('pingxx-sendRefund:' . '退款订单返回', json_encode(['req'=>$refundData, 'res'=>$response], JSON_UNESCAPED_UNICODE), $e);
} }
return $response;
} }
/** /**
...@@ -84,24 +93,32 @@ class PingxxService ...@@ -84,24 +93,32 @@ class PingxxService
*/ */
public function getRefund($orderId, $refundId) { public function getRefund($orderId, $refundId) {
try { try {
FileLog::info('ping++:' . '退款查询发起', json_encode(['orderId'=>$orderId, 'refundId'=>$refundId], JSON_UNESCAPED_UNICODE)); $start = microtime(true);
$ret = OrderRefund::retrieve($orderId, $refundId); $ret = OrderRefund::retrieve($orderId, $refundId);
FileLog::info('ping++:' . '退款查询返回', json_encode(['res'=>$ret], JSON_UNESCAPED_UNICODE));
$end = microtime(true); //计算结束时间
$total_time = round(($end - $start),4) * 1000; //计算耗时
$url = 'pingxx/v1/refund/get';
MonUtil::proxyMon($url, '200', 'bp-pay', $total_time);
FileLog::info('pingxx-getRefund:' . '退款查询返回', json_encode(['req'=>[$orderId, $refundId], 'res'=>$ret], JSON_UNESCAPED_UNICODE));
$respose = json_decode($ret, true); $respose = json_decode($ret, true);
return $respose;
} catch (\Pingpp\Error\Base $e) { } catch (\Pingpp\Error\Base $e) {
// 捕获报错信息 // 捕获报错信息
if ($e->getHttpStatus() != null) { if ($e->getHttpStatus() != null) {
return json_decode($e->getHttpBody(), true); $respose = json_decode($e->getHttpBody(), true);
} else { } else {
return [ $respose = [
'error'=>['message'=>$e->getMessage()], 'error'=>['message'=>$e->getMessage()],
'type'=>'http error', 'type'=>'http error',
]; ];
} }
FileLog::error('pingxx-getRefund:' . '退款查询返回', json_encode(['req'=>[$orderId, $refundId], 'res'=>$respose], JSON_UNESCAPED_UNICODE), $e);
} }
return $respose;
} }
/** /**
...@@ -112,8 +129,8 @@ class PingxxService ...@@ -112,8 +129,8 @@ class PingxxService
public function createOrder($order, $metadata) { public function createOrder($order, $metadata) {
try { try {
FileLog::info('ping++:' . '创建订单发起', json_encode($order, JSON_UNESCAPED_UNICODE));
$royalty_users = []; $royalty_users = [];
$start = microtime(true);
$ret = Order::create( $ret = Order::create(
[ [
"amount" => $order['pay_amount'], "amount" => $order['pay_amount'],
...@@ -130,21 +147,27 @@ class PingxxService ...@@ -130,21 +147,27 @@ class PingxxService
] ]
); );
FileLog::info('ping++:' . '创建订单返回', json_encode(['res'=>$ret], JSON_UNESCAPED_UNICODE)); $end = microtime(true); //计算结束时间
$total_time = round(($end - $start),4) * 1000; //计算耗时
$url = 'pingxx/v1/order/create';
MonUtil::proxyMon($url, '200', 'bp-pay', $total_time);
FileLog::info('pingxx-createOrder:' . '创建订单返回', json_encode(['req'=>[$order, $metadata], 'res'=>$ret], JSON_UNESCAPED_UNICODE));
$respose = json_decode($ret, true); $respose = json_decode($ret, true);
return $respose;
} catch (\Pingpp\Error\Base $e) { } catch (\Pingpp\Error\Base $e) {
// 捕获报错信息 // 捕获报错信息
if ($e->getHttpStatus() != null) { if ($e->getHttpStatus() != null) {
return json_decode($e->getHttpBody(), true); $respose = json_decode($e->getHttpBody(), true);
} else { } else {
return [ $respose = [
'error'=>['message'=>$e->getMessage()], 'error'=>['message'=>$e->getMessage()],
'type'=>'http error', 'type'=>'http error',
]; ];
} }
FileLog::error('pingxx-createOrder:' . '创建订单返回', json_encode(['req'=>[$order, $metadata], 'res'=>$ret], JSON_UNESCAPED_UNICODE), $e);
/** /**
{ {
"error": { "error": {
...@@ -156,30 +179,39 @@ class PingxxService ...@@ -156,30 +179,39 @@ class PingxxService
} }
*/ */
} }
return $respose;
} }
public function pay($orderId, $pay) { public function pay($orderId, $pay) {
try { try {
FileLog::info('ping++:' . '订单pay发起', json_encode($pay, JSON_UNESCAPED_UNICODE)); $start = microtime(true);
$ret = Order::pay($orderId, $pay); $ret = Order::pay($orderId, $pay);
FileLog::info('ping++:' . '订单pay返回', json_encode(['res'=>$ret], JSON_UNESCAPED_UNICODE));
$end = microtime(true); //计算结束时间
$total_time = round(($end - $start),4) * 1000; //计算耗时
$url = 'pingxx/v1/order/pay';
MonUtil::proxyMon($url, '200', 'bp-pay', $total_time);
FileLog::info('pingxx-pay:' . '订单pay返回', json_encode(['req'=>[$orderId, $pay], 'res'=>$ret], JSON_UNESCAPED_UNICODE));
$respose = json_decode($ret, true); $respose = json_decode($ret, true);
return $respose;
} catch (\Pingpp\Error\Base $e) { } catch (\Pingpp\Error\Base $e) {
// 捕获报错信息 // 捕获报错信息
if ($e->getHttpStatus() != null) { if ($e->getHttpStatus() != null) {
return json_decode($e->getHttpBody(), true); $respose = json_decode($e->getHttpBody(), true);
} else { } else {
return [ $respose = [
'error'=>['message'=>$e->getMessage()], 'error'=>['message'=>$e->getMessage()],
'type'=>'http error', 'type'=>'http error',
]; ];
} }
FileLog::error('pingxx-pay:' . '订单pay返回', json_encode(['req'=>[$orderId, $pay], 'res'=>$respose], JSON_UNESCAPED_UNICODE), $e);
} }
return $respose;
} }
...@@ -190,37 +222,32 @@ class PingxxService ...@@ -190,37 +222,32 @@ class PingxxService
public function getOrder($orderId) { public function getOrder($orderId) {
try { try {
FileLog::info('ping++:' . '查询订单发起', json_encode(['orderId'=>$orderId])); $start = microtime(true);
$ret = Order::retrieve($orderId); $ret = Order::retrieve($orderId);
FileLog::info('ping++:' . '查询订单返回', json_encode(['res'=>$ret], JSON_UNESCAPED_UNICODE)); $end = microtime(true); //计算结束时间
$total_time = round(($end - $start),4) * 1000; //计算耗时
$url = 'pingxx/v1/order/get';
MonUtil::proxyMon($url, '200', 'bp-pay', $total_time);
FileLog::info('pingxx-pay:' . '查询订单返回', json_encode(['req'=>[$orderId], 'res'=>$ret], JSON_UNESCAPED_UNICODE));
$respose = json_decode($ret, true); $respose = json_decode($ret, true);
return $respose;
} catch (\Pingpp\Error\Base $e) { } catch (\Pingpp\Error\Base $e) {
// 捕获报错信息 // 捕获报错信息
if ($e->getHttpStatus() != null) { if ($e->getHttpStatus() != null) {
return json_decode($e->getHttpBody(), true); $respose = json_decode($e->getHttpBody(), true);
} else { } else {
return [ $respose = [
'error'=>['message'=>$e->getMessage()], 'error'=>['message'=>$e->getMessage()],
'type'=>'http error', 'type'=>'http error',
]; ];
} }
} FileLog::error('pingxx-pay:' . '查询订单返回', json_encode(['req'=>[$orderId], 'res'=>$ret], JSON_UNESCAPED_UNICODE), $e);
} }
/** return $respose;
* @param $raw
* @param $header
* @return int
* 校验回调是否合法
*/
public function verifySignature($raw, $signature) {
return 1;
$pub_key_path = ROOT_PATH . '/conf/pingpp_rsa_public_key.pem';
$pub_key_contents = file_get_contents($pub_key_path);
return openssl_verify($raw, base64_decode($signature), $pub_key_contents, 'sha256');
} }
} }
\ No newline at end of file
...@@ -4,13 +4,12 @@ application.dispatcher.throwException = 0 ...@@ -4,13 +4,12 @@ application.dispatcher.throwException = 0
application.dispatcher.catchException = 0 application.dispatcher.catchException = 0
application.directory = APP_PATH application.directory = APP_PATH
application.bootstrap = APP_PATH "/Bootstrap.php" application.bootstrap = APP_PATH"/Bootstrap.php"
application.library = APP_PATH"/library" application.library = APP_PATH"/library"
application.library.namespace = "" application.library.namespace = ""
application.modules="Index,Pay" application.modules="Index,Pay"
appid = "pay" appid = "pay"
;AES密钥 ;AES密钥
aes.key = "79b20206d70e09b2" aes.key = "79b20206d70e09b2"
aes.iv = "645410b05b5d1670" aes.iv = "645410b05b5d1670"
...@@ -21,24 +20,30 @@ aes.switch = true ...@@ -21,24 +20,30 @@ aes.switch = true
idgen.partner = "bp" idgen.partner = "bp"
idgen.key = "5cfdb867e96374c7883b31d6928cc4cb" idgen.key = "5cfdb867e96374c7883b31d6928cc4cb"
[exception] [exception]
debug = true debug = true
exception.user.code = -1 exception.user.code = -1
exception.user.msg = "error" exception.user.msg = "用户未定义异常,研发正在赶来的路上..."
exception.sys.code = -1 exception.sys.code = -1
exception.sys.msg = "system error" exception.sys.msg = "系统未定义异常,研发正在赶来的路上..."
[trace] [trace]
trace.open = true trace.open = true
[prod : common : exception] [dingTalk]
dingTalk.tokens[]="78ab018e4f6f18021d08d964cdc5466e4ba902ce78528717c77ebfa512d5671a"
dingTalk.keys[]="SEC5c912c5bd18afc72b861d7ad70677da599fc0f803ee558504b950e4967da7279"
dingTalk.tokens[]="5d754d76cac8c64aad495bc44f481677745ff831aee0517b6e5b3565be6ba69e"
dingTalk.keys[]="SEC0298ad3f80e16df12cd4d6f6c39e961b500e2ff486f4c4377c0e2af8f4539a74"
[prod : common : exception : dingTalk]
pnigxx.appid = "app_9m1ubDG4e1mPXLCG" pnigxx.appid = "app_9m1ubDG4e1mPXLCG"
[pref : common : exception] [pref : common : exception : dingTalk]
pingxx.appid = "app_9m1ubDG4e1mPXLCG" pingxx.appid = "app_9m1ubDG4e1mPXLCG"
[test : common : exception] [test : common : exception : dingTalk]
pingxx.appid = "app_W10Oe5XrvbzHfP4W" pingxx.appid = "app_W10Oe5XrvbzHfP4W"
[dev : common : exception] [dev : common : exception]
......
...@@ -7,7 +7,22 @@ application.dispatcher.throwException = true ...@@ -7,7 +7,22 @@ application.dispatcher.throwException = true
daemon.script_dir = "\\Daemon\\" daemon.script_dir = "\\Daemon\\"
appid = "pay" appid = "pay"
[product : common] [dingTalk]
[pre : common ] dingTalk.tokens[]="78ab018e4f6f18021d08d964cdc5466e4ba902ce78528717c77ebfa512d5671a"
[test: common ] dingTalk.keys[]="SEC5c912c5bd18afc72b861d7ad70677da599fc0f803ee558504b950e4967da7279"
dingTalk.tokens[]="5d754d76cac8c64aad495bc44f481677745ff831aee0517b6e5b3565be6ba69e"
dingTalk.keys[]="SEC0298ad3f80e16df12cd4d6f6c39e961b500e2ff486f4c4377c0e2af8f4539a74"
[product : common : dingTalk]
pnigxx.appid = "app_9m1ubDG4e1mPXLCG"
[pref : common : dingTalk]
pnigxx.appid = "app_9m1ubDG4e1mPXLCG"
[test: common : dingTalk]
pingxx.appid = "app_W10Oe5XrvbzHfP4W"
[dev : common ] [dev : common ]
pingxx.appid = "app_W10Oe5XrvbzHfP4W"
<?php <?php
ini_set("display_errors", "On");//打开错误提示
ini_set("error_reporting",E_ALL);//显示所有错误 $environ = ini_get('yaf.environ');
if(in_array($environ, ['dev'])) {
ini_set("display_errors", "On");
error_reporting(E_ALL);
// 异常信息等级
define('_ERROR_LEVEL', E_ALL);
define('_IS_DEBUG', false);
} else {
ini_set("display_errors", "Off");
error_reporting(E_ALL & ~E_DEPRECATED & ~E_STRICT);
// 异常信息等级
define('_ERROR_LEVEL', E_ALL & ~E_DEPRECATED & ~E_STRICT);
define('_IS_DEBUG', false);
}
/* /*
* cli入口脚本 * cli入口脚本
* cli 配置文件:conf/cli.ini * cli 配置文件:conf/cli.ini
...@@ -19,7 +36,6 @@ define('ROOT_PATH', realpath(__DIR__.'/../')); ...@@ -19,7 +36,6 @@ define('ROOT_PATH', realpath(__DIR__.'/../'));
define('APP_PATH', realpath(__DIR__.'/../application')); define('APP_PATH', realpath(__DIR__.'/../application'));
define('APP_START', microtime(true)); define('APP_START', microtime(true));
require ROOT_PATH . '/vendor/autoload.php';
$application = new Yaf\Application( ROOT_PATH . "/conf/cli.ini"); $application = new Yaf\Application( ROOT_PATH . "/conf/cli.ini");
/** /**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment