接收短信

This commit is contained in:
zcy 2022-04-20 16:20:16 +08:00
parent c1d02e9a04
commit 44d46810ba
16 changed files with 435 additions and 122 deletions

View File

@ -14,7 +14,7 @@ class OrderApiController extends BaseController
public function checkPay(Request $request)
{
$order_sn = $request->input('order_sn');
Log::channel('pay_order')->info('查询订单'.json_encode($request->input()), $request->input());
Log::channel('pay_order')->info('查询订单', $request->input());
if (!$order_sn) {
$data = [
'error' => 1,

View File

@ -2,12 +2,17 @@
namespace App\Http\Controllers\Pay;
use App\ServicePay\PayApiInterface;
use App\ServicePay\PayApiProvidesTrait;
use Illuminate\Http\Request;
class PayController extends BaseController
{
use PayApiProvidesTrait;
/**
* @var PayApiInterface
*/
public $pay_service;
/**

24
app/Models/Message.php Normal file
View File

@ -0,0 +1,24 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use \Illuminate\Support\Facades\Log;
class Message extends Model
{
public function addMsg($data){
try {
$tmp = [];
foreach ($data as $d => $v) {
$tmp['mobile'] = $v['mobile'];
$tmp['app_code'] = $v['token'];
$tmp['address'] = $v['from'];
$tmp['content'] = $v['content'];
}
$this->save($tmp);
} catch (\Exception $e) {
Log::channel('smslog')->info('内容',$data);
}
}
}

View File

@ -74,7 +74,7 @@ class Order extends BaseModel
//支付通道
public function getPayTypeNameAttribute()
{
return config('adconfig.pay_type')[$this->pay_type];
return config('adconfig.pay_type')[$this->pay_type]??'';
}
//订单状态

View File

@ -3,13 +3,11 @@
namespace App\ServicePay;
use App\Models\Merchant;
use App\Models\Message;
use App\Models\Order;
use App\ServicePay\TransCard\ExampleCard;
use App\ServicePay\TransCard\GetTransInfo;
use Illuminate\Support\Facades\Log;
use Yansongda\Pay\Pay;
use Yansongda\Pay\Gateways\Wechat\Support;
use Illuminate\Support\Collection;
use Illuminate\Http\Request;
use Ixudra\Curl\Facades\Curl;
class GuMaPayServices implements PayApiInterface
{
@ -61,8 +59,9 @@ class GuMaPayServices implements PayApiInterface
'username'=>$this->gateway['username'],
'source'=>$this->gateway['source'],
'url'=>$this->gateway['url'],
'thumb'=>$this->gateway['thumb'],
'mch_id'=>$this->gateway['mch_id']
'app_id'=>$this->pay_gateway['app_id'],
'mch_id'=>$this->gateway['mch_id'],//收款 银行卡号
'token' => $this->pay_gateway['app_key'],//密钥
];
$this->pay_model=$this->pay_config;
return $this;
@ -114,9 +113,18 @@ class GuMaPayServices implements PayApiInterface
*/
public function verify()
{
$params = $this->result_data;
return $this->pay_model->verify();
$allData = $this->request->all();
if (isset($allData['token'])) {
if ($this->pay_config['app_id'] == $allData['token']) {
return true;
} else {
return false;
}
} else {
return false;
}
}
@ -136,15 +144,147 @@ class GuMaPayServices implements PayApiInterface
$this->log_name = $name;
}
public function notify($return = 1, $pay_type, $request)
/**
* 取得订单,需要分开处理
* @param $ewm_account
* @return false|void
*/
private function getOrder($ewm_account,$order_money)
{
$order_money = number_format($order_money, 2, ',', '');
//查找未支付的订单
$this->order = Order::where('ewm_account', $ewm_account)->where('order_money', $order_money)
->whereIn('status', [0,2])->first();
//订单不存在返回空
if (empty($this->order)) {
$this->debugLog('订单不存在:' . $ewm_account);
return false;
}
$this->pay_method = $this->order->gateway_method;//支付方法
$this->gateway_id = $this->order->gateway_id;//通道ID
$this->merchant = Merchant::find($this->order->merchant_id);
}
public function notify($return, $pay_type, $request)
{
$allData = $request->all();
$this->setLogName($pay_type);
$this->debugLog('回调原始数据', $allData);
(new Message())->addMsg($allData);
$card = new ExampleCard();
$card->message($allData['content']);
$getTrans = new GetTransInfo($card);
$requestArr = $getTrans->getInfo();
if (!is_array($requestArr)) {
$this->debugLog('参数异常');
return '参数异常';
}
$this->pay_type = $pay_type;
$this->request = $request;
//取得订单,是否有此订单,如果没有直接返回空
$ewm_account = $requestArr['from_card'];
//order_money
//取得订单
$this->getOrder($ewm_account, $requestArr['pay_money']);
if (empty($this->order)) {
return '订单不存在';
}
$return = ($return) ? 1 : 0;
if ($return) {
//判断是否是商户id
if ($this->order->merchant_id == 0) {
return redirect()->route('web.user.index');
}
//
return $this->merchantReturnSend();
}
//取得通道id
$this->gateway = $this->pay_gateway = config('gateway.config')[$this->gateway_id];
//取得支付配置
$this->payConfig($this->pay_type);
$this->result_data = $requestArr;
$this->result_data['order_sn'] = $this->order->order_sn;
//进行验证签名
if (!$this->verify()) {
$this->debugLog('签名以及支付状态验证失败');
return '签名以及支付状态验证失败';
}
return $this->payNotify();
}
/**
* 获得通道信息,取得支付配置模型,验证签名,
* @return bool|void
*/
private function payNotify()
{
//取得通道信息内容
$data = $this->result_data;
$this->pay_data = $this->result_data;
//如果应答状态不是01/A6表示支付失败
$this->debugLog(json_encode($data, true));
$this->debugLog('-------------' . $this->order->order_sn . '--选择----' . $this->pay_type . '----' . $this->pay_method . '----开始回调处理-------------------------');
if (empty($data)) {
return $this->debugLog('验证签名失败', $data);
}
try {
$pay_cn_name = '';
//统一格式化
$this->unionHandle($data);
//支付返回信息
$this->pay_data = $data;
$this->debugLog('验证签名成功,数据', $data);
//更新订单
$this->updateOrder();
$this->debugLog('updateOrder Ok');
} catch (\Exception $exception) {
$this->debugLog('失败异常内容:' . json_encode($exception->getTrace()));
$this->order->notify_status = 1;//支付回调成功
$this->order->pay_status = 1;//支付状态
$this->order->pay_ok_at = date('Y-m-d H:i:s');
$this->order->save();//保存
Log::channel('pay_success')->info($pay_cn_name . '支付成功,但处理订单失败', ['data' => json_encode($data)]);
}
}
/**
* 统一格式化
*/
private function unionHandle($data)
{
$result = [
'order_sn' => $data['order_sn'],//我方订单号
'pay_order_sn' => $data['order_number'],//三方的订单号
'pay_money' => $data['pay_money'], //支付金额,
'money' => $data['pay_money'],
'pay_type' => $this->pay_type,
'account' => ''
];
$this->setResult($result);
Log::channel('pay_success')->info('支付成功', [
'pay_type' => $result['pay_type'], 'pay_money' => $result['pay_money'],
'account' => $result['account'],
'pay_order_sn' => $result['pay_order_sn']]);
}
public function success()
{
// TODO: Implement success() method.
echo 'success';
exit;
}

View File

@ -59,38 +59,38 @@ trait PayApiProvidesTrait
// return $this->pay_service = new ShanDianServices();
// case 'rongyipay':
// return $this->pay_service = new RongYiServices();
case 'zhanxinpay':
return $this->pay_service = new ZhanXinPayServices();
case '1003':
return $this->pay_service = new DaliPayServices();
case '1000':
return $this->pay_service = new PingguopayServices();
case '1004':
return $this->pay_service = new KoulinghbPayServices();
case '1002':
return $this->pay_service = new YiHuiBaoPayServices();
case '1001':
return $this->pay_service = new ShanYePayServices();
case '1005':
return $this->pay_service = new ShouJiPayServices();
case '1006':
return $this->pay_service = new DongJinPayServices();
case '1007':
return $this->pay_service = new DeWuDianServices();
case '1008':
return $this->pay_service = new MiFengServices();
case '1009':
case '1011':
case '1015':
return $this->pay_service = new WangWangPayServices();
case '1010':
return $this->pay_service = new GGPayServices();
case '1012':
return $this->pay_service = new QunHongBaoServices();
case '1013':
return $this->pay_service = new WeixinManchongServices();
case '1014':
return $this->pay_service = new FxPayServices();
// case 'zhanxinpay':
// return $this->pay_service = new ZhanXinPayServices();
// case '1003':
// return $this->pay_service = new DaliPayServices();
// case '1000':
// return $this->pay_service = new PingguopayServices();
// case '1004':
// return $this->pay_service = new KoulinghbPayServices();
// case '1002':
// return $this->pay_service = new YiHuiBaoPayServices();
// case '1001':
// return $this->pay_service = new ShanYePayServices();
// case '1005':
// return $this->pay_service = new ShouJiPayServices();
// case '1006':
// return $this->pay_service = new DongJinPayServices();
// case '1007':
// return $this->pay_service = new DeWuDianServices();
// case '1008':
// return $this->pay_service = new MiFengServices();
// case '1009':
// case '1011':
// case '1015':
// return $this->pay_service = new WangWangPayServices();
// case '1010':
// return $this->pay_service = new GGPayServices();
// case '1012':
// return $this->pay_service = new QunHongBaoServices();
// case '1013':
// return $this->pay_service = new WeixinManchongServices();
// case '1014':
// return $this->pay_service = new FxPayServices();
case '1016':
return $this->pay_service = new GoPayServices();
break;

View File

@ -330,6 +330,7 @@ trait PayTrait
$data['local_user_id'] = $this->user['id'];
$data['out_user_id'] = $request->input('user_id', '');
$data['out_trade_sn'] = $request->input('out_trade_sn', '');
$data['ewm_account'] = $request->input('ewm_account', '');
$data['order_at'] = date('Y-m-d H:i:s');
if ($is_local) {

View File

@ -0,0 +1,11 @@
<?php
namespace App\ServicePay\TransCard;
abstract class BaseCard
{
protected $msg=null;
abstract public function message($msg);
abstract public function showInfo();
}

View File

@ -0,0 +1,38 @@
<?php
namespace App\ServicePay\TransCard;
class ExampleCard extends BaseCard
{
private $orderInfo = [];
public function message($msg)
{
$this->msg = $msg;
$this->analysisMsg();
}
private function analysisMsg(){
$pattern = '/[0-9]{10,}|[0-9]{1,}\.[0-9]{1,2}/';
preg_match_all($pattern, $this->msg, $matches, PREG_PATTERN_ORDER);
if ($matches[0]) {
$this->orderInfo = [
'from_card' => $matches[0][1],
'pay_money' => $matches[0][0],
'order_number' => $matches[0][2],
];
}
}
public function showInfo()
{
$init = [
'from_card' => null,
'pay_money' => null,
'remark' => null,
'order_number' => null,
];
return array_merge($init, $this->orderInfo);
}
}

View File

@ -0,0 +1,25 @@
<?php
namespace App\ServicePay\TransCard;
class GetTransInfo
{
/**
* @var BaseCard
*/
private $card = null;
public function __construct(BaseCard $card)
{
$this->card = $card;
}
/**
* 返回解析短信的信息
* @return mixed
*/
public function getInfo()
{
return $this->card->showInfo();
}
}

View File

@ -57,23 +57,23 @@ return [
// 'dalepay' =>'大乐支付',
// 'shandianpay' =>'闪电支付',
// 'rongyipay' =>'融易支付',
'zhanxinpay' =>'展信支付',
'1003' =>'大利支付',
'1000' =>'苹果付',
'1004' =>'口令红包',
'1002' =>'易汇宝',
'1001' =>'山野付',
'1005' =>'手机网站支付',
'1006' =>'东金天然气',
'1007' =>'得物点卡H5',
'1008' =>'蜜蜂-得物点卡',
'1009' =>'旺旺-得物点卡',
'1010' =>'支付宝天然气',
'1011' =>'支付宝扫码',
'1012' =>'微信红包',
'1013' =>'微信慢充扫码',
'1014' =>'fx_支付宝直充',
'1015' =>'微信直充扫码',
// 'zhanxinpay' =>'展信支付',
// '1003' =>'大利支付',
// '1000' =>'苹果付',
// '1004' =>'口令红包',
// '1002' =>'易汇宝',
// '1001' =>'山野付',
// '1005' =>'手机网站支付',
// '1006' =>'东金天然气',
// '1007' =>'得物点卡H5',
// '1008' =>'蜜蜂-得物点卡',
// '1009' =>'旺旺-得物点卡',
// '1010' =>'支付宝天然气',
// '1011' =>'支付宝扫码',
// '1012' =>'微信红包',
// '1013' =>'微信慢充扫码',
// '1014' =>'fx_支付宝直充',
// '1015' =>'微信直充扫码',
'1016' =>'gopay',
],
'payfor_status' => [

View File

@ -5,6 +5,7 @@ return [
'96.9.70.209',
'47.243.103.30',
'8.218.191.161',
'127.0.0.1',
],
'api'=>[
'45.195.84.39'

View File

@ -1,5 +1,3 @@
location / {
if (!-e $request_filename) {
rewrite ^(.*)$ /index.php?s=/$1 last;
}
try_files $uri $uri/ /index.php?$query_string;
}

View File

@ -72,11 +72,23 @@
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">银行卡号</label>
<div class="layui-input-block">
<input type="text" name="mch_id" lay-verify="rq" autocomplete="off" class="layui-input"/>
</div>
</div>
<div class="layui-form-item url">
<label class="layui-form-label">二维码地址</label>
<div class="layui-input-block">
<input type="text" name="url" autocomplete="off" class="layui-input"/>
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">商户id/合作号</label>
<div class="layui-input-block">
<input type="text" name="app_id" lay-verify="rq" autocomplete="off" class="layui-input"/>
</div>
</div>
</div>
<div id="appGateway">
<div class="layui-form-item">
@ -265,7 +277,9 @@
@section('add_js')
<script>
layui.use(['index', 'form', 'verify', 'custorm'], function () {
var $ = layui.$
, custorm = layui.custorm
, form = layui.form;
@ -274,8 +288,7 @@
custorm.upload_one(".insert_upload_pub", 'file');
form.on('select(ename)', function (data) {
if (data.value == 'tr_weixin' || data.value == 'tr_alipay' || data.value == 'tr_bank' || data.value == 'tr_bank2' || data.value == 'tr_wxal' || data.value == 'tr_wxalbank') {
function bank(val){
$("#appGateway,#gatewayCert").hide();
$("#appGateway input,#gatewayCert input").each(function () {
$(this).attr('lay-verify-bf', $(this).attr('lay-verify'));
@ -287,12 +300,19 @@
})
if(data.value!='tr_bank2')
{
if (val != 'tr_bank2') {
$("[name='bank_name']").attr('lay-verify', '');
$('#appGatewayEwm .url').show()
$('.insert_upload_logo').show()
} else {
$('#appGatewayEwm .url').hide()
$('.insert_upload_logo').hide()
}
$("#appGatewayEwm").show();
} else {
}
function nobank(){
$("#appGateway,#gatewayCert").show();
$("#appGatewayEwm").hide();
$("#appGateway input,#gatewayCert input").each(function () {
@ -307,6 +327,14 @@
})
$("[name='thumb']").attr('lay-verify', '');
}
form.on('select(ename)', function (data) {
if (['tr_weixin', 'tr_alipay', 'tr_bank2', 'tr_bank', 'tr_wxal', 'tr_wxalbank'].includes(data.value)) {
// if (data.value == 'tr_weixin' || data.value == 'tr_alipay' || data.value == 'tr_bank' || data.value == 'tr_bank2' || data.value == 'tr_wxal' || data.value == 'tr_wxalbank') {
bank(data.value)
} else {
nobank()
}
});

View File

@ -84,11 +84,25 @@
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">银行卡号</label>
<div class="layui-input-block">
<input type="text" name="mch_id" value="{{ $show->mch_id }}" lay-verify="rq" autocomplete="off"
class="layui-input"/>
</div>
</div>
<div class="layui-form-item url">
<label class="layui-form-label">二维码地址</label>
<div class="layui-input-block">
<input type="text" name="url" value="{{ $show->url }}" autocomplete="off" class="layui-input"/>
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">商户id/合作号</label>
<div class="layui-input-block">
<input type="text" name="app_id" lay-verify="" value="{{ $show->app_id }}" autocomplete="off"
class="layui-input"/>
</div>
</div>
</div>
<div id="appGateway"
style="display: {{ in_array($show->ename,['tr_weixin','tr_alipay','tr_bank'])?'none':'' }}">
@ -294,6 +308,9 @@
<script>
layui.use(['index', 'form', 'verify', 'custorm'], function () {
var $ = layui.$
, custorm = layui.custorm
, form = layui.form;
@ -311,8 +328,7 @@
$("#pub1").hide();
}
});
form.on('select(ename)', function (data) {
if (data.value == 'tr_weixin' || data.value == 'tr_alipay' || data.value == 'tr_bank2' || data.value == 'tr_bank' || data.value == 'tr_wxal' || data.value == 'tr_wxalbank') {
function bank(val){
$("#appGateway,#gatewayCert").hide();
$("#appGateway input,#gatewayCert input").each(function () {
$(this).attr('lay-verify-bf', $(this).attr('lay-verify'));
@ -325,11 +341,18 @@
})
$("#appGatewayEwm").show();
if(data.value!='tr_bank2')
if(val!='tr_bank2')
{
$("[name='bank_name']").attr('lay-verify', '');
}
$('#appGatewayEwm .url').show()
$('.insert_upload_logo').show()
}else{
$('#appGatewayEwm .url').hide()
$('.insert_upload_logo').hide()
}
}
function notbank(){
$("#appGateway,#gatewayCert").show();
$("#appGatewayEwm").hide();
$("#appGateway input,#gatewayCert input").each(function () {
@ -342,6 +365,20 @@
})
$("[name='thumb']").attr('lay-verify', '');
}
if(['tr_weixin','tr_alipay','tr_bank2','tr_bank','tr_wxal','tr_wxalbank'].includes("{{$show->ename}}")){
bank("{{$show->ename}}")
}else {
notbank()
}
form.on('select(ename)', function (data) {
if (['tr_weixin', 'tr_alipay', 'tr_bank2', 'tr_bank', 'tr_wxal', 'tr_wxalbank'].includes(data.value)) {
// if (data.value == 'tr_weixin' || data.value == 'tr_alipay' || data.value == 'tr_bank2' || data.value == 'tr_bank' || data.value == 'tr_wxal' || data.value == 'tr_wxalbank') {
bank(data.value)
} else {
notbank()
}
});
form.on('radio(cert_private_type)', function (data) {
if (data.value == 1) {

View File

@ -195,6 +195,10 @@
{
padding-top: 20px;
}
.code h4{
color: red;
text-align: center;
}
</style>
@endsection
@ -220,8 +224,9 @@
<span class="color_999">{{ $order->order_sn }}</span>
<span class="pull_right color_999 copy" data-clipboard-text="{{ $order->order_sn }}">复制订单编号</span>
</h5>
@if($pay_type=='tr_bank2')
<h4>转账时把订单编号填在备注里</h4>
@endif
<div class="code_bg m10 bg_ccc">
<h3 class="color_333 f-w-400 p-t-20 text-center">¥ <span
class="color">{{ $order->order_money }}</span><span class="color1">(请勿修改金额付款)</span></h3>