Commit f7f80289 authored by wuxiaoli's avatar wuxiaoli

生成二维码

parent 116d4bca
......@@ -30,6 +30,6 @@ Route::name('order.')->prefix('order')->middleware(['auth.check:admin'])->group(
Route::get('/index', 'index')->name('index');
Route::post('/add', 'add')->name('add');
Route::put('/edit', 'edit')->name('edit');
Route::delete('/delete', 'delete')->name('delete');
Route::post('/simple', 'simple')->name('simple');
});
});
......@@ -24,4 +24,15 @@ class Pay extends BaseController {
return response()->json($this->data);
}
public function nativepc(Request $request, PayService $service){
try {
$this->data['data'] = $service->getNativePayData('native', $request);
} catch (\Exception $th) {
$this->data['message'] = $th->getMessage();
$this->data['code'] = $th->getCode();
}
return response()->json($this->data);
}
}
\ No newline at end of file
......@@ -127,4 +127,58 @@ class PayService {
return $response->toArray();
}
/**
* 用户扫码支付
*/
public function getNativePayData($from,$request){
$config = Config::get('wechat.miniapp');
$app = new Application($config);
$utils = $app->getUtils();
$type = $request->input('type', 'order');
$description = "";
switch ($type) {
case 'order':
$data = app('Modules\Order\Services\OrderService')->getjsPayData($request, $from);
$description = "订单支付";
break;
default:
$data = app('Modules\Order\Services\OrderService')->getjsPayData($request, $from);
$description = "订单支付";
break;
}
$payData = [
'mchid' => $config['mch_id'],
'appid' => $config['app_id'],
'out_trade_no' => $data->order_no,
'description' => $description,
'notify_url' => request()->root() .'/api/wechat/notify/'.$type,
'amount' => [
'total' => intval($data->amount * 100),
'currency' => 'CNY',
],
];
$response = $app->getClient()->postJson("v3/pay/transactions/native", $payData);
if($response->isFailed()){
throw new \Exception($response->getContent(), $response->getStatusCode());
}
$prepayId = $response->toArray()['code_url'];
switch ($type) {
case 'order':
Order::where('id', $data->id)->update(['pay_no' => $prepayId, 'pay_type' => $from]);
break;
default:
Order::where('id', $data->id)->update(['pay_no' => $prepayId, 'pay_type' => $from]);
break;
}
return $utils->buildMiniAppConfig($prepayId, $config['app_id'], 'RSA');
}
}
\ No newline at end of file
......@@ -42,7 +42,7 @@ class TransferService
'transfer_amount' => $pars['total_amount'],
'transfer_remark' => $body,
'openid' => $openid,
'user_name'=> WechatUtil::getEncrypt($batch_name,$config['public_key']),
//'user_name'=> WechatUtil::getEncrypt($batch_name,$config['public_key']),
];//转账明细列表
$pars['notify_url'] = request()->root() .'/api/wechat/notify/transfer';
......
......@@ -23,6 +23,7 @@ Route::name('wechat.')->prefix('wechat')->middleware(['auth.check:api'])->group(
Route::post('miniapp', 'miniapp')->name('miniapp');
});
});
Route::post('/wechat/pay/nativepc', [Modules\Wechat\Controllers\Api\Pay::class, 'nativepc']);
Route::post('/wechat/notify/order', [Modules\Wechat\Controllers\Api\Notify::class, 'order']);
Route::post('/wechat/notify/payment', [Modules\Wechat\Controllers\Api\Notify::class, 'payment']);
......
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