first commit
This commit is contained in:
@@ -0,0 +1 @@
|
||||
deny from all
|
||||
@@ -0,0 +1,406 @@
|
||||
<?php
|
||||
namespace app\admin\controller;
|
||||
|
||||
use think\App;
|
||||
use think\Db;
|
||||
use think\facade\Session;
|
||||
use app\service\QrcodeServer;
|
||||
use Zxing\QrReader;
|
||||
|
||||
class Index
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
return 'by:vone';
|
||||
}
|
||||
|
||||
public function getReturn($code = 1,$msg = "成功",$data = null){
|
||||
return array("code"=>$code,"msg"=>$msg,"data"=>$data);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function getMain(){
|
||||
if (!Session::has("admin")){
|
||||
return json($this->getReturn(-1,"没有登录"));
|
||||
}
|
||||
$today = strtotime(date("Y-m-d"),time());
|
||||
|
||||
$todayOrder = Db::name("pay_order")
|
||||
->where("create_date >=".$today)
|
||||
->where("create_date <=".($today+86400))
|
||||
->count();
|
||||
|
||||
|
||||
$todaySuccessOrder = Db::name("pay_order")
|
||||
->where("state >=1")
|
||||
->where("create_date >=".$today)
|
||||
->where("create_date <=".($today+86400))
|
||||
->count();
|
||||
|
||||
|
||||
|
||||
$todayCloseOrder = Db::name("pay_order")
|
||||
->where("state",-1)
|
||||
->where("create_date >=".$today)
|
||||
->where("create_date <=".($today+86400))
|
||||
->count();
|
||||
|
||||
$todayMoney = Db::name("pay_order")
|
||||
->where("state >=1")
|
||||
->where("create_date >=".$today)
|
||||
->where("create_date <=".($today+86400))
|
||||
->sum("price");
|
||||
|
||||
|
||||
$countOrder = Db::name("pay_order")
|
||||
->count();
|
||||
$countMoney = Db::name("pay_order")
|
||||
->where("state >=1")
|
||||
->sum("price");
|
||||
|
||||
$v = Db::query("SELECT VERSION();");
|
||||
$v=$v[0]['VERSION()'];
|
||||
|
||||
if(function_exists("gd_info")) {
|
||||
$gd_info = @gd_info();
|
||||
$gd = $gd_info["GD Version"];
|
||||
}else{
|
||||
$gd = '<font color="red">GD库未开启!</font>';
|
||||
}
|
||||
|
||||
return json($this->getReturn(1,"成功",array(
|
||||
"todayOrder"=>$todayOrder,
|
||||
"todaySuccessOrder"=>$todaySuccessOrder,
|
||||
"todayCloseOrder"=>$todayCloseOrder,
|
||||
"todayMoney"=>round($todayMoney,2),
|
||||
"countOrder"=>$countOrder,
|
||||
"countMoney"=>round($countMoney),
|
||||
|
||||
"PHP_VERSION"=>PHP_VERSION,
|
||||
"PHP_OS"=>PHP_OS,
|
||||
"SERVER"=>$_SERVER ['SERVER_SOFTWARE'],
|
||||
"MySql"=>$v,
|
||||
"Thinkphp"=>"v".App::VERSION,
|
||||
"RunTime"=>$this->sys_uptime(),
|
||||
"ver"=>"v".config("ver"),
|
||||
"gd"=>$gd,
|
||||
)));
|
||||
|
||||
}
|
||||
private function sys_uptime() {
|
||||
$output='';
|
||||
if (false === ($str = @file("/proc/uptime"))) return false;
|
||||
$str = explode(" ", implode("", $str));
|
||||
$str = trim($str[0]);
|
||||
$min = $str / 60;
|
||||
$hours = $min / 60;
|
||||
$days = floor($hours / 24);
|
||||
$hours = floor($hours - ($days * 24));
|
||||
$min = floor($min - ($days * 60 * 24) - ($hours * 60));
|
||||
if ($days !== 0) $output .= $days."天";
|
||||
if ($hours !== 0) $output .= $hours."小时";
|
||||
if ($min !== 0) $output .= $min."分钟";
|
||||
return $output;
|
||||
}
|
||||
public function checkUpdate(){
|
||||
if (!Session::has("admin")){
|
||||
return json($this->getReturn(-1,"没有登录"));
|
||||
}
|
||||
$ver = $this->getCurl("https://raw.githubusercontent.com/szvone/vmqphp/master/ver");
|
||||
$ver = explode("|",$ver);
|
||||
|
||||
if (sizeof($ver)==2 && $ver[0]!=config("ver")){
|
||||
return json($this->getReturn(1,"[v".$ver[0]."已于".$ver[1]."发布]","https://github.com/szvone/vmqphp"));
|
||||
}else{
|
||||
return json($this->getReturn(0,"程序是最新版"));
|
||||
}
|
||||
}
|
||||
|
||||
public function getSettings(){
|
||||
if (!Session::has("admin")){
|
||||
return json($this->getReturn(-1,"没有登录"));
|
||||
}
|
||||
$user = Db::name("setting")->where("vkey","user")->find();
|
||||
$pass = Db::name("setting")->where("vkey","pass")->find();
|
||||
$notifyUrl = Db::name("setting")->where("vkey","notifyUrl")->find();
|
||||
$returnUrl = Db::name("setting")->where("vkey","returnUrl")->find();
|
||||
$key = Db::name("setting")->where("vkey","key")->find();
|
||||
$lastheart = Db::name("setting")->where("vkey","lastheart")->find();
|
||||
$lastpay = Db::name("setting")->where("vkey","lastpay")->find();
|
||||
$jkstate = Db::name("setting")->where("vkey","jkstate")->find();
|
||||
$close = Db::name("setting")->where("vkey","close")->find();
|
||||
$payQf = Db::name("setting")->where("vkey","payQf")->find();
|
||||
$wxpay = Db::name("setting")->where("vkey","wxpay")->find();
|
||||
$zfbpay = Db::name("setting")->where("vkey","zfbpay")->find();
|
||||
if ($key['vvalue']==""){
|
||||
$key['vvalue'] = md5(time());
|
||||
Db::name("setting")->where("vkey","key")->update(array(
|
||||
"vvalue"=>$key['vvalue']
|
||||
));
|
||||
}
|
||||
|
||||
return json($this->getReturn(1,"成功",array(
|
||||
"user"=>$user['vvalue'],
|
||||
"pass"=>$pass['vvalue'],
|
||||
"notifyUrl"=>$notifyUrl['vvalue'],
|
||||
"returnUrl"=>$returnUrl['vvalue'],
|
||||
"key"=>$key['vvalue'],
|
||||
"lastheart"=>$lastheart['vvalue'],
|
||||
"lastpay"=>$lastpay['vvalue'],
|
||||
"jkstate"=>$jkstate['vvalue'],
|
||||
"close"=>$close['vvalue'],
|
||||
"payQf"=>$payQf['vvalue'],
|
||||
"wxpay"=>$wxpay['vvalue'],
|
||||
"zfbpay"=>$zfbpay['vvalue'],
|
||||
|
||||
)));
|
||||
|
||||
|
||||
}
|
||||
public function saveSetting(){
|
||||
if (!Session::has("admin")){
|
||||
return json($this->getReturn(-1,"没有登录"));
|
||||
}
|
||||
Db::name("setting")->where("vkey","user")->update(array("vvalue"=>input("user")));
|
||||
Db::name("setting")->where("vkey","pass")->update(array("vvalue"=>input("pass")));
|
||||
Db::name("setting")->where("vkey","notifyUrl")->update(array("vvalue"=>input("notifyUrl")));
|
||||
Db::name("setting")->where("vkey","returnUrl")->update(array("vvalue"=>input("returnUrl")));
|
||||
Db::name("setting")->where("vkey","key")->update(array("vvalue"=>input("key")));
|
||||
Db::name("setting")->where("vkey","close")->update(array("vvalue"=>input("close")));
|
||||
Db::name("setting")->where("vkey","payQf")->update(array("vvalue"=>input("payQf")));
|
||||
Db::name("setting")->where("vkey","wxpay")->update(array("vvalue"=>input("wxpay")));
|
||||
Db::name("setting")->where("vkey","zfbpay")->update(array("vvalue"=>input("zfbpay")));
|
||||
|
||||
|
||||
return json($this->getReturn());
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
public function addPayQrcode(){
|
||||
if (!Session::has("admin")){
|
||||
return json($this->getReturn(-1,"没有登录"));
|
||||
}
|
||||
$db = Db::name("pay_qrcode")->insert(array(
|
||||
"type"=>input("type"),
|
||||
"pay_url"=>input("pay_url"),
|
||||
"price"=>input("price"),
|
||||
));
|
||||
return json($this->getReturn());
|
||||
|
||||
}
|
||||
|
||||
public function getPayQrcodes(){
|
||||
if (!Session::has("admin")){
|
||||
return json($this->getReturn(-1,"没有登录"));
|
||||
}
|
||||
$page = input("page");
|
||||
$size = input("limit");
|
||||
|
||||
$obj = Db::table('pay_qrcode')->page($page,$size);
|
||||
|
||||
$obj = $obj->where("type",input("type"));
|
||||
|
||||
$array = $obj->order("id","desc")->select();
|
||||
|
||||
//echo $obj->getLastSql();
|
||||
return json(array(
|
||||
"code"=>0,
|
||||
"msg"=>"获取成功",
|
||||
"data"=>$array,
|
||||
"count"=> $obj->count()
|
||||
));
|
||||
}
|
||||
public function delPayQrcode(){
|
||||
if (!Session::has("admin")){
|
||||
return json($this->getReturn(-1,"没有登录"));
|
||||
}
|
||||
Db::name("pay_qrcode")->where("id",input("id"))->delete();
|
||||
return json($this->getReturn());
|
||||
|
||||
}
|
||||
|
||||
public function getOrders(){
|
||||
if (!Session::has("admin")){
|
||||
return json($this->getReturn(-1,"没有登录"));
|
||||
}
|
||||
$page = input("page");
|
||||
$size = input("limit");
|
||||
|
||||
$obj = Db::table('pay_order')->page($page,$size);
|
||||
if (input("type")){
|
||||
$obj = $obj->where("type",input("type"));
|
||||
}
|
||||
if (input("state")){
|
||||
$obj = $obj->where("state",input("state"));
|
||||
}
|
||||
|
||||
|
||||
$array = $obj->order("id","desc")->select();
|
||||
|
||||
//echo $obj->getLastSql();
|
||||
return json(array(
|
||||
"code"=>0,
|
||||
"msg"=>"获取成功",
|
||||
"data"=>$array,
|
||||
"count"=> $obj->count()
|
||||
));
|
||||
}
|
||||
public function delOrder(){
|
||||
if (!Session::has("admin")){
|
||||
return json($this->getReturn(-1,"没有登录"));
|
||||
}
|
||||
$res = Db::name("pay_order")->where("id",input("id"))->find();
|
||||
|
||||
Db::name("pay_order")->where("id",input("id"))->delete();
|
||||
if ($res['state']==0){
|
||||
Db::name("tmp_price")
|
||||
->where("oid",$res['order_id'])
|
||||
->delete();
|
||||
}
|
||||
|
||||
return json($this->getReturn());
|
||||
|
||||
}
|
||||
|
||||
public function setBd(){
|
||||
if (!Session::has("admin")){
|
||||
return json($this->getReturn(-1,"没有登录"));
|
||||
}
|
||||
|
||||
$res = Db::name("pay_order")->where("id",input("id"))->find();
|
||||
|
||||
if ($res){
|
||||
|
||||
$url = $res['notify_url'];
|
||||
|
||||
$res2 = Db::name("setting")->where("vkey","key")->find();
|
||||
$key = $res2['vvalue'];
|
||||
|
||||
$p = "payId=".$res['pay_id']."¶m=".$res['param']."&type=".$res['type']."&price=".$res['price']."&reallyPrice=".$res['really_price'];
|
||||
|
||||
$sign = $res['pay_id'].$res['param'].$res['type'].$res['price'].$res['really_price'].$key;
|
||||
$p = $p . "&sign=".md5($sign);
|
||||
if (strpos($url,"?")===false){
|
||||
$url = $url."?".$p;
|
||||
}else{
|
||||
$url = $url."&".$p;
|
||||
}
|
||||
|
||||
$re = $this->getCurl($url);
|
||||
|
||||
if ($re=="success"){
|
||||
if ($res['state']==0){
|
||||
Db::name("tmp_price")
|
||||
->where("oid",$res['order_id'])
|
||||
->delete();
|
||||
}
|
||||
|
||||
Db::name("pay_order")->where("id",$res['id'])->update(array("state"=>1));
|
||||
|
||||
return json($this->getReturn());
|
||||
}else{
|
||||
return json($this->getReturn(-2,"补单失败",$re));
|
||||
}
|
||||
}else{
|
||||
return json($this->getReturn(-1,"订单不存在"));
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
public function delGqOrder(){
|
||||
if (!Session::has("admin")){
|
||||
return json($this->getReturn(-1,"没有登录"));
|
||||
}
|
||||
Db::name("pay_order")->where("state","-1")->delete();
|
||||
return json($this->getReturn());
|
||||
}
|
||||
public function delLastOrder(){
|
||||
if (!Session::has("admin")){
|
||||
return json($this->getReturn(-1,"没有登录"));
|
||||
}
|
||||
|
||||
Db::name("pay_order")->where("create_date <".(time()-604800))->delete();
|
||||
return json($this->getReturn());
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public function enQrcode($url){
|
||||
|
||||
$qr_code = new QrcodeServer(['generate'=>"display","size",200]);
|
||||
$content = $qr_code->createServer($url);
|
||||
|
||||
return response($content,200,['Content-Length'=>strlen($content)])->contentType('image/png');
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//获取客户IP
|
||||
public function ip() {
|
||||
|
||||
return $_SERVER['REMOTE_ADDR'];
|
||||
}
|
||||
//发送Http请求
|
||||
function getCurl($url, $post = 0, $cookie = 0, $header = 0, $nobaody = 0)
|
||||
{
|
||||
$ch = curl_init();
|
||||
curl_setopt($ch, CURLOPT_URL, $url);
|
||||
curl_setopt($ch, CURLOPT_TIMEOUT, 15);
|
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
|
||||
$klsf[] = 'Accept:*/*';
|
||||
$klsf[] = 'Accept-Language:zh-cn';
|
||||
//$klsf[] = 'Content-Type:application/json';
|
||||
$klsf[] = 'User-Agent:Mozilla/5.0 (iPhone; CPU iPhone OS 11_2_1 like Mac OS X) AppleWebKit/604.4.7 (KHTML, like Gecko) Mobile/15C153 MicroMessenger/6.6.1 NetType/WIFI Language/zh_CN';
|
||||
$klsf[] = 'Referer:'.$url;
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, $klsf);
|
||||
if ($post) {
|
||||
curl_setopt($ch, CURLOPT_POST, 1);
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
|
||||
}
|
||||
if ($header) {
|
||||
curl_setopt($ch, CURLOPT_HEADER, true);
|
||||
}
|
||||
if ($cookie) {
|
||||
curl_setopt($ch, CURLOPT_COOKIE, $cookie);
|
||||
}
|
||||
if ($nobaody) {
|
||||
curl_setopt($ch, CURLOPT_NOBODY, 1);
|
||||
}
|
||||
curl_setopt($ch, CURLOPT_TIMEOUT,60);
|
||||
curl_setopt($ch, CURLOPT_ENCODING, 'gzip');
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
||||
$ret = curl_exec($ch);
|
||||
curl_close($ch);
|
||||
return $ret;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2006-2016 http://thinkphp.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: yunwuxin <448901948@qq.com>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
return [];
|
||||
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2006-2016 http://thinkphp.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: 流年 <liu21st@gmail.com>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
// 应用公共文件
|
||||
@@ -0,0 +1,615 @@
|
||||
<?php
|
||||
namespace app\index\controller;
|
||||
|
||||
use think\Db;
|
||||
use think\facade\Session;
|
||||
|
||||
class Index
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
$url = "http://www.5cctv.net/wp-content/plugins/erphpdown/payment/vmq/notify.php?payId=190717101020112222981¶m=order[7876632]&type=1&price=1&reallyPrice=1&sign=2398a2492db0616381a85c1fedc51a11";
|
||||
return $this->getCurl($url);
|
||||
|
||||
//return 'by:vone';
|
||||
}
|
||||
|
||||
public function getReturn($code = 1, $msg = "成功", $data = null)
|
||||
{
|
||||
return array("code" => $code, "msg" => $msg, "data" => $data);
|
||||
}
|
||||
|
||||
//后台用户登录
|
||||
public function login()
|
||||
{
|
||||
$user = input("user");
|
||||
$pass = input("pass");
|
||||
|
||||
$_user = Db::name("setting")->where("vkey", "user")->find();
|
||||
if ($user != $_user["vvalue"]) {
|
||||
return json($this->getReturn(-1, "账号或密码错误"));
|
||||
}
|
||||
|
||||
$_pass = Db::name("setting")->where("vkey", "pass")->find();
|
||||
if ($pass != $_pass["vvalue"]) {
|
||||
return json($this->getReturn(-1, "账号或密码错误"));
|
||||
}
|
||||
|
||||
Session::set("admin", 1);
|
||||
|
||||
return json($this->getReturn());
|
||||
}
|
||||
|
||||
|
||||
//后台菜单
|
||||
public function getMenu()
|
||||
{
|
||||
if (!Session::has("admin")) {
|
||||
return json($this->getReturn(-1, "没有登录"));
|
||||
}
|
||||
|
||||
|
||||
$menu = array(
|
||||
array(
|
||||
"name" => "系统设置",
|
||||
"type" => "url",
|
||||
"url" => "admin/setting.html?t=" . time(),
|
||||
),
|
||||
array(
|
||||
"name" => "监控端设置",
|
||||
"type" => "url",
|
||||
"url" => "admin/jk.html?t=" . time(),
|
||||
),
|
||||
array(
|
||||
"name" => "微信二维码",
|
||||
"type" => "menu",
|
||||
"node" => array(
|
||||
array(
|
||||
"name" => "添加",
|
||||
"type" => "url",
|
||||
"url" => "admin/addwxqrcode.html?t=" . time(),
|
||||
),
|
||||
array(
|
||||
"name" => "管理",
|
||||
"type" => "url",
|
||||
"url" => "admin/wxqrcodelist.html?t=" . time(),
|
||||
)
|
||||
),
|
||||
), array(
|
||||
"name" => "支付宝二维码",
|
||||
"type" => "menu",
|
||||
"node" => array(
|
||||
array(
|
||||
"name" => "添加",
|
||||
"type" => "url",
|
||||
"url" => "admin/addzfbqrcode.html?t=" . time(),
|
||||
),
|
||||
array(
|
||||
"name" => "管理",
|
||||
"type" => "url",
|
||||
"url" => "admin/zfbqrcodelist.html?t=" . time(),
|
||||
)
|
||||
),
|
||||
), array(
|
||||
"name" => "订单列表",
|
||||
"type" => "url",
|
||||
"url" => "admin/orderlist.html?t=" . time(),
|
||||
), array(
|
||||
"name" => "Api说明",
|
||||
"type" => "url",
|
||||
"url" => "api.html?t=" . time(),
|
||||
)
|
||||
);
|
||||
|
||||
return json($menu);
|
||||
|
||||
}
|
||||
|
||||
//创建订单
|
||||
public function createOrder()
|
||||
{
|
||||
$this->closeEndOrder();
|
||||
|
||||
$payId = input("payId");
|
||||
if (!$payId || $payId == "") {
|
||||
return json($this->getReturn(-1, "请传入商户订单号"));
|
||||
}
|
||||
$type = input("type");
|
||||
if (!$type || $type == "") {
|
||||
return json($this->getReturn(-1, "请传入支付方式=>1|微信 2|支付宝"));
|
||||
}
|
||||
if ($type != 1 && $type != 2) {
|
||||
return json($this->getReturn(-1, "支付方式错误=>1|微信 2|支付宝"));
|
||||
}
|
||||
|
||||
$price = input("price");
|
||||
if (!$price || $price == "") {
|
||||
return json($this->getReturn(-1, "请传入订单金额"));
|
||||
}
|
||||
if ($price <= 0) {
|
||||
return json($this->getReturn(-1, "订单金额必须大于0"));
|
||||
}
|
||||
|
||||
$sign = input("sign");
|
||||
if (!$sign || $sign == "") {
|
||||
return json($this->getReturn(-1, "请传入签名"));
|
||||
}
|
||||
|
||||
$isHtml = input("isHtml");
|
||||
if (!$isHtml || $isHtml == "") {
|
||||
$isHtml = 0;
|
||||
}
|
||||
$param = input("param");
|
||||
if (!$param) {
|
||||
$param = "";
|
||||
}
|
||||
|
||||
$res = Db::name("setting")->where("vkey", "key")->find();
|
||||
$key = $res['vvalue'];
|
||||
|
||||
if (input("notifyUrl")) {
|
||||
$notify_url = input("notifyUrl");
|
||||
} else {
|
||||
$res = Db::name("setting")->where("vkey", "notifyUrl")->find();
|
||||
$notify_url = $res['vvalue'];
|
||||
}
|
||||
|
||||
if (input("returnUrl")) {
|
||||
$return_url = input("returnUrl");
|
||||
} else {
|
||||
$res = Db::name("setting")->where("vkey", "returnUrl")->find();
|
||||
$return_url = $res['vvalue'];
|
||||
}
|
||||
|
||||
|
||||
$_sign = md5($payId . $param . $type . $price . $key);
|
||||
if ($sign != $_sign) {
|
||||
return json($this->getReturn(-1, "签名错误"));
|
||||
}
|
||||
|
||||
$jkstate = Db::name("setting")->where("vkey", "jkstate")->find();
|
||||
$jkstate = $jkstate['vvalue'];
|
||||
if ($jkstate!="1"){
|
||||
return json($this->getReturn(-1, "监控端状态异常,请检查"));
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
$reallyPrice = bcmul($price ,100);
|
||||
|
||||
$payQf = Db::name("setting")->where("vkey", "payQf")->find();
|
||||
$payQf = $payQf['vvalue'];
|
||||
|
||||
|
||||
$orderId = date("YmdHms") . rand(1, 9) . rand(1, 9) . rand(1, 9) . rand(1, 9);
|
||||
|
||||
$ok = false;
|
||||
for ($i = 0; $i < 10; $i++) {
|
||||
$tmpPrice = $reallyPrice . "-" . $type;
|
||||
|
||||
$row = Db::execute("INSERT IGNORE INTO tmp_price (price,oid) VALUES ('" . $tmpPrice . "','".$orderId."')");
|
||||
if ($row) {
|
||||
$ok = true;
|
||||
break;
|
||||
}
|
||||
if ($payQf == 1) {
|
||||
$reallyPrice++;
|
||||
} else if ($payQf == 2) {
|
||||
$reallyPrice--;
|
||||
}
|
||||
}
|
||||
|
||||
if (!$ok) {
|
||||
return json($this->getReturn(-1, "订单超出负荷,请稍后重试"));
|
||||
}
|
||||
//echo $reallyPrice;
|
||||
|
||||
$reallyPrice = bcdiv($reallyPrice, 100,2);
|
||||
|
||||
if ($type == 1) {
|
||||
$payUrl = Db::name("setting")->where("vkey", "wxpay")->find();
|
||||
$payUrl = $payUrl['vvalue'];
|
||||
|
||||
} else if ($type == 2) {
|
||||
$payUrl = Db::name("setting")->where("vkey", "zfbpay")->find();
|
||||
$payUrl = $payUrl['vvalue'];
|
||||
}
|
||||
|
||||
if ($payUrl == "") {
|
||||
return json($this->getReturn(-1, "请您先进入后台配置程序"));
|
||||
}
|
||||
$isAuto = 1;
|
||||
$_payUrl = Db::name("pay_qrcode")
|
||||
->where("price", $reallyPrice)
|
||||
->where("type", $type)
|
||||
->find();
|
||||
if ($_payUrl) {
|
||||
$payUrl = $_payUrl['pay_url'];
|
||||
$isAuto = 0;
|
||||
}
|
||||
|
||||
|
||||
$res = Db::name("pay_order")->where("pay_id", $payId)->find();
|
||||
if ($res) {
|
||||
return json($this->getReturn(-1, "商户订单号已存在"));
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
$createDate = time();
|
||||
$data = array(
|
||||
"close_date" => 0,
|
||||
"create_date" => $createDate,
|
||||
"is_auto" => $isAuto,
|
||||
"notify_url" => $notify_url,
|
||||
"order_id" => $orderId,
|
||||
"param" => $param,
|
||||
"pay_date" => 0,
|
||||
"pay_id" => $payId,
|
||||
"pay_url" => $payUrl,
|
||||
"price" => $price,
|
||||
"really_price" => $reallyPrice,
|
||||
"return_url" => $return_url,
|
||||
"state" => 0,
|
||||
"type" => $type
|
||||
|
||||
);
|
||||
|
||||
|
||||
Db::name("pay_order")->insert($data);
|
||||
|
||||
|
||||
//return "<script>window.location.href = '/payPage/pay.html?orderId=" + c.getOrderId() + "'</script>";
|
||||
|
||||
if ($isHtml == 1) {
|
||||
|
||||
echo "<script>window.location.href = 'payPage/pay.html?orderId=" . $orderId . "'</script>";
|
||||
|
||||
} else {
|
||||
$time = Db::name("setting")->where("vkey", "close")->find();
|
||||
$data = array(
|
||||
"payId" => $payId,
|
||||
"orderId" => $orderId,
|
||||
"payType" => $type,
|
||||
"price" => $price,
|
||||
"reallyPrice" => $reallyPrice,
|
||||
"payUrl" => $payUrl,
|
||||
"isAuto" => $isAuto,
|
||||
"state" => 0,
|
||||
"timeOut" => $time['vvalue'],
|
||||
"date" => $createDate
|
||||
);
|
||||
return json($this->getReturn(1, "成功", $data));
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
//获取订单信息
|
||||
public function getOrder()
|
||||
{
|
||||
|
||||
$res = Db::name("pay_order")->where("order_id", input("orderId"))->find();
|
||||
if ($res){
|
||||
$time = Db::name("setting")->where("vkey", "close")->find();
|
||||
|
||||
$data = array(
|
||||
"payId" => $res['pay_id'],
|
||||
"orderId" => $res['order_id'],
|
||||
"payType" => $res['type'],
|
||||
"price" => $res['price'],
|
||||
"reallyPrice" => $res['really_price'],
|
||||
"payUrl" => $res['pay_url'],
|
||||
"isAuto" => $res['is_auto'],
|
||||
"state" => $res['state'],
|
||||
"timeOut" => $time['vvalue'],
|
||||
"date" => $res['create_date']
|
||||
);
|
||||
return json($this->getReturn(1, "成功", $data));
|
||||
}else{
|
||||
return json($this->getReturn(-1, "云端订单编号不存在"));
|
||||
}
|
||||
}
|
||||
//查询订单状态
|
||||
public function checkOrder()
|
||||
{
|
||||
$res = Db::name("pay_order")->where("order_id", input("orderId"))->find();
|
||||
if ($res){
|
||||
if ($res['state']==0){
|
||||
return json($this->getReturn(-1, "订单未支付"));
|
||||
}
|
||||
if ($res['state']==-1){
|
||||
return json($this->getReturn(-1, "订单已过期"));
|
||||
}
|
||||
|
||||
$res2 = Db::name("setting")->where("vkey","key")->find();
|
||||
$key = $res2['vvalue'];
|
||||
|
||||
$res['price'] = number_format($res['price'],2,".","");
|
||||
$res['really_price'] = number_format($res['really_price'],2,".","");
|
||||
|
||||
|
||||
$p = "payId=".$res['pay_id']."¶m=".$res['param']."&type=".$res['type']."&price=".$res['price']."&reallyPrice=".$res['really_price'];
|
||||
|
||||
$sign = $res['pay_id'].$res['param'].$res['type'].$res['price'].$res['really_price'].$key;
|
||||
$p = $p . "&sign=".md5($sign);
|
||||
|
||||
$url = $res['return_url'];
|
||||
|
||||
|
||||
|
||||
if (strpos($url,"?")===false){
|
||||
$url = $url."?".$p;
|
||||
}else{
|
||||
$url = $url."&".$p;
|
||||
}
|
||||
|
||||
return json($this->getReturn(1, "成功", $url));
|
||||
}else{
|
||||
return json($this->getReturn(-1, "云端订单编号不存在"));
|
||||
}
|
||||
|
||||
}
|
||||
//关闭订单
|
||||
public function closeOrder(){
|
||||
$res2 = Db::name("setting")->where("vkey","key")->find();
|
||||
$key = $res2['vvalue'];
|
||||
$orderId = input("orderId");
|
||||
|
||||
$_sign = $orderId.$key;
|
||||
|
||||
if (md5($_sign)!=input("sign")){
|
||||
return json($this->getReturn(-1, "签名校验不通过"));
|
||||
}
|
||||
|
||||
$res = Db::name("pay_order")->where("order_id",$orderId)->find();
|
||||
|
||||
if ($res){
|
||||
if ($res['state']!=0){
|
||||
return json($this->getReturn(-1, "订单状态不允许关闭"));
|
||||
}
|
||||
Db::name("pay_order")->where("order_id",$orderId)->update(array("state"=>-1,"close_date"=>time()));
|
||||
Db::name("tmp_price")
|
||||
->where("oid",$res['order_id'])
|
||||
->delete();
|
||||
return json($this->getReturn(1, "成功"));
|
||||
}else{
|
||||
return json($this->getReturn(-1, "云端订单编号不存在"));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
//获取监控端状态
|
||||
public function getState(){
|
||||
$res2 = Db::name("setting")->where("vkey","key")->find();
|
||||
$key = $res2['vvalue'];
|
||||
$t = input("t");
|
||||
|
||||
$_sign = $t.$key;
|
||||
|
||||
if (md5($_sign)!=input("sign")){
|
||||
return json($this->getReturn(-1, "签名校验不通过"));
|
||||
}
|
||||
|
||||
$res = Db::name("setting")->where("vkey","lastheart")->find();
|
||||
$lastheart = $res['vvalue'];
|
||||
$res = Db::name("setting")->where("vkey","lastpay")->find();
|
||||
$lastpay = $res['vvalue'];
|
||||
$res = Db::name("setting")->where("vkey","jkstate")->find();
|
||||
$jkstate = $res['vvalue'];
|
||||
|
||||
return json($this->getReturn(1, "成功",array("lastheart"=>$lastheart,"lastpay"=>$lastpay,"jkstate"=>$jkstate)));
|
||||
|
||||
}
|
||||
|
||||
//App心跳接口
|
||||
public function appHeart(){
|
||||
$this->closeEndOrder();
|
||||
|
||||
$res2 = Db::name("setting")->where("vkey","key")->find();
|
||||
$key = $res2['vvalue'];
|
||||
$t = input("t");
|
||||
|
||||
$_sign = $t.$key;
|
||||
|
||||
if (md5($_sign)!=input("sign")){
|
||||
return json($this->getReturn(-1, "签名校验不通过"));
|
||||
}
|
||||
|
||||
// $jg = time()*1000 - $t;
|
||||
// if ($jg>50000 || $jg<-50000){
|
||||
// return json($this->getReturn(-1, "客户端时间错误"));
|
||||
// }
|
||||
|
||||
Db::name("setting")->where("vkey","lastheart")->update(array("vvalue"=>time()));
|
||||
Db::name("setting")->where("vkey","jkstate")->update(array("vvalue"=>1));
|
||||
return json($this->getReturn());
|
||||
}
|
||||
//App推送付款数据接口
|
||||
public function appPush(){
|
||||
$this->closeEndOrder();
|
||||
|
||||
$res2 = Db::name("setting")->where("vkey","key")->find();
|
||||
$key = $res2['vvalue'];
|
||||
$t = input("t");
|
||||
$type = input("type");
|
||||
$price = input("price");
|
||||
|
||||
$_sign = $type.$price.$t.$key;
|
||||
|
||||
if (md5($_sign)!=input("sign")){
|
||||
return json($this->getReturn(-1, "签名校验不通过"));
|
||||
}
|
||||
|
||||
// $jg = time()*1000 - $t;
|
||||
// if ($jg>50000 || $jg<-50000){
|
||||
// return json($this->getReturn(-1, "客户端时间错误"));
|
||||
// }
|
||||
|
||||
Db::name("setting")
|
||||
->where("vkey","lastpay")
|
||||
->update(
|
||||
array(
|
||||
"vvalue"=>time()
|
||||
)
|
||||
);
|
||||
|
||||
$res = Db::name("pay_order")
|
||||
->where("really_price",$price)
|
||||
->where("state",0)
|
||||
->where("type",$type)
|
||||
->find();
|
||||
|
||||
|
||||
|
||||
if ($res){
|
||||
|
||||
Db::name("tmp_price")
|
||||
->where("oid",$res['order_id'])
|
||||
->delete();
|
||||
|
||||
Db::name("pay_order")->where("id",$res['id'])->update(array("state"=>1,"pay_date"=>time(),"close_date"=>time()));
|
||||
|
||||
$url = $res['notify_url'];
|
||||
|
||||
$res2 = Db::name("setting")->where("vkey","key")->find();
|
||||
$key = $res2['vvalue'];
|
||||
|
||||
$p = "payId=".$res['pay_id']."¶m=".$res['param']."&type=".$res['type']."&price=".$res['price']."&reallyPrice=".$res['really_price'];
|
||||
|
||||
$sign = $res['pay_id'].$res['param'].$res['type'].$res['price'].$res['really_price'].$key;
|
||||
$p = $p . "&sign=".md5($sign);
|
||||
|
||||
if (strpos($url,"?")===false){
|
||||
$url = $url."?".$p;
|
||||
}else{
|
||||
$url = $url."&".$p;
|
||||
}
|
||||
|
||||
|
||||
$re = $this->getCurl($url);
|
||||
if ($re=="success"){
|
||||
return json($this->getReturn());
|
||||
}else{
|
||||
Db::name("pay_order")->where("id",$res['id'])->update(array("state"=>2));
|
||||
|
||||
return json($this->getReturn(-1,"异步通知失败"));
|
||||
}
|
||||
|
||||
|
||||
}else{
|
||||
$data = array(
|
||||
"close_date" => 0,
|
||||
"create_date" => time(),
|
||||
"is_auto" => 0,
|
||||
"notify_url" => "",
|
||||
"order_id" => "无订单转账",
|
||||
"param" => "无订单转账",
|
||||
"pay_date" => 0,
|
||||
"pay_id" => "无订单转账",
|
||||
"pay_url" => "",
|
||||
"price" => $price,
|
||||
"really_price" => $price,
|
||||
"return_url" => "",
|
||||
"state" => 1,
|
||||
"type" => $type
|
||||
|
||||
);
|
||||
|
||||
Db::name("pay_order")->insert($data);
|
||||
return json($this->getReturn());
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
//关闭过期订单接口(请用定时器至少1分钟调用一次)
|
||||
public function closeEndOrder(){
|
||||
$res = Db::name("setting")->where("vkey","lastheart")->find();
|
||||
$lastheart = $res['vvalue'];
|
||||
if ((time()-$lastheart)>60){
|
||||
Db::name("setting")->where("vkey","jkstate")->update(array("vvalue"=>0));
|
||||
}
|
||||
|
||||
|
||||
|
||||
$time = Db::name("setting")->where("vkey", "close")->find();
|
||||
|
||||
$closeTime = time()-60*$time['vvalue'];
|
||||
$close_date = time();
|
||||
|
||||
$res = Db::name("pay_order")
|
||||
->where("create_date <=".$closeTime)
|
||||
->where("state",0)
|
||||
->update(array("state"=>-1,"close_date"=>$close_date));
|
||||
|
||||
if ($res){
|
||||
$rows = Db::name("pay_order")->where("close_date",$close_date)->select();
|
||||
foreach ($rows as $row){
|
||||
Db::name("tmp_price")
|
||||
->where("oid",$row['order_id'])
|
||||
->delete();
|
||||
}
|
||||
|
||||
$rows = Db::name("tmp_price")->select();
|
||||
foreach ($rows as $row){
|
||||
$re = Db::name("pay_order")->where("order_id",$row['oid'])->find();
|
||||
if ($re){
|
||||
|
||||
}else{
|
||||
Db::name("tmp_price")
|
||||
->where("oid",$row['oid'])
|
||||
->delete();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return json($this->getReturn(1,"成功清理".$res."条订单"));
|
||||
}else{
|
||||
return json($this->getReturn(1,"没有等待清理的订单"));
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
//发送Http请求
|
||||
private function getCurl($url, $post = 0, $cookie = 0, $header = 0, $nobaody = 0)
|
||||
{
|
||||
$ch = curl_init();
|
||||
curl_setopt($ch, CURLOPT_URL, $url);
|
||||
curl_setopt($ch, CURLOPT_TIMEOUT, 15);
|
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
|
||||
$klsf[] = 'Accept:*/*';
|
||||
$klsf[] = 'Accept-Language:zh-cn';
|
||||
//$klsf[] = 'Content-Type:application/json';
|
||||
$klsf[] = 'User-Agent:Mozilla/5.0 (iPhone; CPU iPhone OS 11_2_1 like Mac OS X) AppleWebKit/604.4.7 (KHTML, like Gecko) Mobile/15C153 MicroMessenger/6.6.1 NetType/WIFI Language/zh_CN';
|
||||
$klsf[] = 'Referer:'.$url;
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, $klsf);
|
||||
if ($post) {
|
||||
curl_setopt($ch, CURLOPT_POST, 1);
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
|
||||
}
|
||||
if ($header) {
|
||||
curl_setopt($ch, CURLOPT_HEADER, true);
|
||||
}
|
||||
if ($cookie) {
|
||||
curl_setopt($ch, CURLOPT_COOKIE, $cookie);
|
||||
}
|
||||
if ($nobaody) {
|
||||
curl_setopt($ch, CURLOPT_NOBODY, 1);
|
||||
}
|
||||
curl_setopt($ch, CURLOPT_TIMEOUT,60);
|
||||
curl_setopt($ch, CURLOPT_ENCODING, 'gzip');
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
||||
$ret = curl_exec($ch);
|
||||
curl_close($ch);
|
||||
return $ret;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2006~2018 http://thinkphp.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: liu21st <liu21st@gmail.com>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
// 应用容器绑定定义
|
||||
return [
|
||||
];
|
||||
@@ -0,0 +1,109 @@
|
||||
<?php
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: vone
|
||||
* Date: 2019/4/16
|
||||
* Time: 22:13
|
||||
*/
|
||||
|
||||
namespace app\service;
|
||||
|
||||
|
||||
use Endroid\QrCode\ErrorCorrectionLevel;
|
||||
use Endroid\QrCode\LabelAlignment;
|
||||
use Endroid\QrCode\QrCode;
|
||||
|
||||
class QrcodeServer
|
||||
{
|
||||
protected $_qr;
|
||||
protected $_encoding = 'UTF-8'; // 编码类型
|
||||
protected $_size = 180; // 二维码大小
|
||||
protected $_logo = false; // 是否需要带logo的二维码
|
||||
protected $_logo_url = ''; // logo图片路径
|
||||
protected $_logo_size = 80; // logo大小
|
||||
protected $_title = false; // 是否需要二维码title
|
||||
protected $_title_content = ''; // title内容
|
||||
protected $_generate = 'display'; // display-直接显示 writefile-写入文件
|
||||
protected $_file_name = './static/qrcode'; // 写入文件路径
|
||||
const MARGIN = 10; // 二维码内容相对于整张图片的外边距
|
||||
const WRITE_NAME = 'png'; // 写入文件的后缀名
|
||||
const FOREGROUND_COLOR = ['r' => 0, 'g' => 0, 'b' => 0, 'a' => 0]; // 前景色
|
||||
const BACKGROUND_COLOR = ['r' => 255, 'g' => 255, 'b' => 255, 'a' => 0]; // 背景色
|
||||
|
||||
public function __construct($config) {
|
||||
isset($config['generate']) && $this->_generate = $config['generate'];
|
||||
isset($config['encoding']) && $this->_encoding = $config['encoding'];
|
||||
isset($config['size']) && $this->_size = $config['size'];
|
||||
isset($config['logo']) && $this->_logo = $config['logo'];
|
||||
isset($config['logo_url']) && $this->_logo_url = $config['logo_url'];
|
||||
isset($config['logo_size']) && $this->_logo_size = $config['logo_size'];
|
||||
isset($config['title']) && $this->_title = $config['title'];
|
||||
isset($config['title_content']) && $this->_title_content = $config['title_content'];
|
||||
isset($config['file_name']) && $this->_file_name = $config['file_name'];
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成二维码
|
||||
* @param $content //需要写入的内容
|
||||
* @return array | page input
|
||||
*/
|
||||
public function createServer($content) {
|
||||
$this->_qr = new QrCode($content);
|
||||
$this->_qr->setSize($this->_size);
|
||||
$this->_qr->setWriterByName(self::WRITE_NAME);
|
||||
$this->_qr->setMargin(self::MARGIN);
|
||||
$this->_qr->setEncoding($this->_encoding);
|
||||
$this->_qr->setErrorCorrectionLevel(ErrorCorrectionLevel::HIGH); // 容错率
|
||||
$this->_qr->setForegroundColor(self::FOREGROUND_COLOR);
|
||||
$this->_qr->setBackgroundColor(self::BACKGROUND_COLOR);
|
||||
// 是否需要title
|
||||
if ($this->_title) {
|
||||
$this->_qr->setLabel($this->_title_content, 16, null, LabelAlignment::CENTER);
|
||||
}
|
||||
// 是否需要logo
|
||||
if ($this->_logo) {
|
||||
$this->_qr->setLogoPath($this->_logo_url);
|
||||
$this->_qr->setLogoWidth($this->_logo_size);
|
||||
}
|
||||
|
||||
$this->_qr->setValidateResult(false);
|
||||
|
||||
if ($this->_generate == 'display') {
|
||||
// 展示二维码
|
||||
// 前端调用 例:<img src="http://localhost/qr.php?url=base64_url_string">
|
||||
header('Content-Type: ' . $this->_qr->getContentType());
|
||||
return $this->_qr->writeString();
|
||||
} else if ($this->_generate == 'writefile') {
|
||||
// 写入文件
|
||||
$file_name = $this->_file_name;
|
||||
return $this->generateImg($file_name);
|
||||
} else {
|
||||
return ['success' => false, 'message' => 'the generate type not found', 'data' => ''];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成文件
|
||||
* @param $file_name //目录文件 例: /tmp
|
||||
* @return array
|
||||
*/
|
||||
public function generateImg($file_name) {
|
||||
$file_path = $file_name . DIRECTORY_SEPARATOR . uniqid() . '.' . self::WRITE_NAME;
|
||||
|
||||
if (!file_exists($file_name)) {
|
||||
mkdir($file_name, 0777, true);
|
||||
}
|
||||
|
||||
try {
|
||||
$this->_qr->writeFile($file_path);
|
||||
$data = [
|
||||
'url' => $file_path,
|
||||
'ext' => self::WRITE_NAME,
|
||||
];
|
||||
return ['success' => true, 'message' => 'write qrimg success', 'data' => $data];
|
||||
} catch (\Exception $e) {
|
||||
return ['success' => false, 'message' => $e->getMessage(), 'data' => ''];
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2006~2018 http://thinkphp.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: liu21st <liu21st@gmail.com>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
// 应用行为扩展定义文件
|
||||
return [
|
||||
// 应用初始化
|
||||
'app_init' => [],
|
||||
// 应用开始
|
||||
'app_begin' => [],
|
||||
// 模块初始化
|
||||
'module_init' => [],
|
||||
// 操作开始执行
|
||||
'action_begin' => [],
|
||||
// 视图内容过滤
|
||||
'view_filter' => [],
|
||||
// 日志写入
|
||||
'log_write' => [],
|
||||
// 应用结束
|
||||
'app_end' => [],
|
||||
];
|
||||
Reference in New Issue
Block a user