This commit is contained in:
2022-09-09 17:03:30 +08:00
parent 7f930b2287
commit 0270a2ca32
2 changed files with 35 additions and 13 deletions

View File

@@ -3,6 +3,7 @@
namespace app\controller; namespace app\controller;
use app\model\AppUser; use app\model\AppUser;
use app\model\Payment;
use EasyWeChat\Factory; use EasyWeChat\Factory;
use EasyWeChat\OfficialAccount\Application; use EasyWeChat\OfficialAccount\Application;
use think\facade\Config; use think\facade\Config;
@@ -93,26 +94,26 @@ class Wechat
$order = \app\model\Order::find($orderId); $order = \app\model\Order::find($orderId);
$notifyUrl = Route::buildUrl('wechat/paid') $notifyUrl = Route::buildUrl('wechat/paid')
->suffix(false) ->suffix(false)
->domain(true) ->domain(true)
->build(); ->build();
dump($notifyUrl);
dump($order); dump(Payment::create([
exit(); 'order_id' => $order->id,
]));
$config = Config::get('wechat.payment'); $config = Config::get('wechat.payment');
$payment = Factory::payment($config); $payment = Factory::payment($config);
$unify = $payment->order->unify([ // $unify = $payment->order->unify([
'body' => '商品订单', // 'body' => '商品订单',
'out_trade_no' => time(), // 'out_trade_no' => time(),
'total_fee' => 100, // 'total_fee' => 100,
'notify_url' => $notifyUrl, // 'notify_url' => $notifyUrl,
'trade_type' => 'JSAPI', // 'trade_type' => 'JSAPI',
'openid' => $user->openid, // 'openid' => $user->openid,
]); // ]);
dump($unify); // dump($unify);
// $prepayId = $unify->prepay_id; // $prepayId = $unify->prepay_id;
// $jssdk = $payment->jssdk->bridgeConfig($prepayId); // $jssdk = $payment->jssdk->bridgeConfig($prepayId);
// return View::fetch('', ['jssdk' => $jssdk]); // return View::fetch('', ['jssdk' => $jssdk]);

21
app/model/Payment.php Normal file
View File

@@ -0,0 +1,21 @@
<?php
namespace app\model;
use think\Model;
use think\model\relation\BelongsTo;
class Payment extends Model
{
protected $autoWriteTimestamp = true;
public function onBeforeInsert()
{
$this->trade_no = time();
}
public function orders(): BelongsTo
{
return $this->belongsTo(Order::class);
}
}