Commit 5998d11c authored by zazaname's avatar zazaname

支付回调

parent c9493749
......@@ -12,6 +12,7 @@ class ExampleController extends Controller
public function test(Request $request){
$this->dispatch(new ExampleJob(11111));
dispatch(new ExampleJob("fuck"));
var_dump("cdcd");
}
}
......@@ -4,6 +4,7 @@ namespace App\Http\Controllers;
use App\Http\Service\PayService;
use Illuminate\Http\JsonResponse;
use Illuminate\Support\Facades\Log;
class PayController extends Controller
{
......@@ -41,6 +42,7 @@ class PayController extends Controller
* 渠道支付回调,平台标识找sdk配置,验签,通过则向CP发起发货通知
*/
public function verBack(){
Log::info( "渠道回调日志:".file_get_contents('php://input'));
$this->checkParam(['app_id','ver']);
$data = $this->paySv->verBack($this->requestData);
return is_array($data) ? json($data) : $data;
......
......@@ -64,6 +64,7 @@ class Jiuzi implements ISdkFactory
return [
'order_id' => $request['order_num'],
'money' => $request['money'],
'channel_order_id' => $request['channel_order_id'],
'result' => $this->result('200','发货成功',$request['order_num'])
];
}
......
......@@ -12,6 +12,7 @@ use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Redis;
use RuntimeException;
use WpOrg\Requests\Requests;
class PayService
{
......@@ -145,11 +146,12 @@ class PayService
$sdkManager = new SdkManager();
// 返回渠道订单号+订单金额[单位元]
$payInfo = $sdkManager->pay($verInfo, $gameInfo, $params);
if (!isset($params['order_id']) && !isset($params['money'])) {
if (!isset($payInfo['order_id']) && !isset($payInfo['money'])) {
return $payInfo['result'];
}
$orderModel = DB::table('app_order');
// 更新回调时间+金额
DB::table('app_order')->where(['order_id' => $payInfo['order_id']])->update(['status' => 1, 'amount'=>$payInfo['money'],'dateline' => time()]);
$orderModel->where(['order_id' => $payInfo['order_id']])->update(['status' => 1, 'amount'=>$payInfo['money'],'channel_order_id'=>$payInfo['channel_order_id'],'dateline' => time()]);
// 保存回调日志
DB::table('app_callback_log')->insert([
'order_id' => $payInfo['order_id'],
......@@ -158,9 +160,32 @@ class PayService
'reqresult' => var_export($payInfo,true),
'reqtime' => time(),
]);
// 通知CP发货,redis队列,后台发货, 订单号|appid|渠道号
$list = "{$payInfo['order_id']}|{$params['app_id']}|{$params['ver']}";
Redis::lpush('send_order_list', $list);
// 获取订单信息
$orderInfo = $orderModel->where(['order_id' => $payInfo['order_id']])->first();
// 通知CP发货,组装post参数,并签名
$post_params = [
'order_id' => $orderInfo->order_id,
'good_name' => $orderInfo->subject,
'cp_order_id' => $orderInfo->cp_order_id,
'uid' => $orderInfo->uid,
'money' => $orderInfo->money,
'app_id' => $orderInfo->appid,
'service_id' => $orderInfo->server_id,
'service_name' => $orderInfo->server_name,
'role_id' => $orderInfo->role_id,
'role_name' => $orderInfo->role_name,
'time' => time(),
'pay_status' => $orderInfo->status,
'extend' => $orderInfo->extra_info,
];
ksort($params);
$signStr = http_build_query($params)."&paykey=".$gameInfo->paykey;
$params['sign'] = md5($signStr);
$response = Requests::post($gameInfo->send_url,['Accept' => 'application/json'],$post_params)->body;
$response_arr = json_decode($response,true);
if($response_arr['code'] === 200) {
$orderModel->where(['order_id' => $payInfo['order_id']])->update(['gstatus' => 1]);
}
// 返回渠道要求返回的提示 成功|失败
return $payInfo['result'];
}
......
......@@ -2,12 +2,16 @@
namespace App\Jobs;
//use Illuminate\Contracts\Bus\SelfHandling;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Bus\SelfHandling;
use Illuminate\Contracts\Queue\ShouldQueue;
class ExampleJob extends Job implements ShouldQueue
class ExampleJob extends Job implements SelfHandling, ShouldQueue
{
use InteractsWithQueue, SerializesModels;
private $cc;
/**
* Create a new job instance.
......@@ -27,7 +31,7 @@ class ExampleJob extends Job implements ShouldQueue
public function handle()
{
sleep(5);
echo getmypid().'-'.time();
dump($this->cc);
// echo getmypid().'-'.time();
// dump($this->cc);
}
}
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