DSSHOP 功能-在線支付

2022-03-18 17:51 更新

功能說明

  • 默認(rèn)只支持微信小程序和微信公眾平臺(tái),APP因需要開放者賬號(hào)暫時(shí)無法開通,其它家的懶的搞,等有業(yè)務(wù)需求了再說
  • 支持下單、退款(退款僅支持一次操作,且退款后需要同步才能完成在線退款,未發(fā)現(xiàn)微信有走退款回調(diào)接口)

參數(shù)說明

請(qǐng)求參數(shù)

屬性 類型 默認(rèn)值 必填 說明
id number 訂單ID
platform string 支付平臺(tái) alipay:支付寶 weixin:微信支付
type string 支付類型 goodsIndent:商品訂單

示例代碼:

public function weixinPayment($body,$fee,$openid,$trade_type='JSAPI'){
    $number= orderNumber();
    $config = config('wechat.payment.default');
    $config['notify_url'] = request()->root().'/api/v1/app/paymentNotify';
    $app = Factory::payment($config);
    $result = $app->order->unify([
        'body' => $body,
        'out_trade_no' => $number,
        'total_fee' => $fee,
        'trade_type' => $trade_type,
        'openid' => $openid,
    ]);
    $return =[
        'result'=>'error',
        'msg'=>'支付異常,請(qǐng)聯(lián)系管理員'
    ];
    if ($result['return_code'] == 'SUCCESS' && $result['result_code'] == 'SUCCESS') {
        $prepayId = $result['prepay_id'];
        $config = $app->jssdk->sdkConfig($prepayId);
        $return =[
            'result'=>'ok',
            'msg'=>$config,
            'number'=>$number
        ];
    }
    if ($result['return_code'] == 'FAIL' && array_key_exists('return_msg', $result)) {
        $return =[
            'result'=>'error',
            'msg'=>$result['return_msg']
        ];
    }
    return $return;
}

返回參數(shù)

屬性 類型 默認(rèn)值 必填 說明
result string 返回狀態(tài),成功:ok 失敗:error
code string 錯(cuò)誤碼,當(dāng)result為error時(shí)需填寫
msg string 錯(cuò)誤原因,當(dāng)result為error時(shí)需填寫
number string 訂單號(hào),當(dāng)result為ok時(shí)需填寫

新加支付說明

  • 首先得先確認(rèn)標(biāo)識(shí),在前端支付頁(yè),添加支付平臺(tái),并設(shè)置唯一標(biāo)識(shí)
  • 后臺(tái)?App\Models\v1\MiniProgram?復(fù)制一份?weixinPayment?方法,將?weixin?換成上一步設(shè)置的標(biāo)識(shí)
  • 完成支付接口對(duì)接,按返回參數(shù)返回即可

新加支付類型說明

  • 首先在前端添加支付類型,如充值,然后設(shè)置唯一標(biāo)識(shí)
  • 后臺(tái)添加很簡(jiǎn)單,只需要添加三個(gè)觀察者,然后編寫對(duì)應(yīng)的業(yè)務(wù)代碼即可

#商品訂單支付生成
#api\app\Observers\PaymentLog\GoodIndentPaymentCreateObserver.php
#商品訂單支付完成
#api\app\Observers\PaymentLog\GoodIndentPaymentSucceedObserver.php
#商品訂單退款
#api\app\Observers\PaymentLog\GoodIndentRefundObserver.php


以上內(nèi)容是否對(duì)您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號(hào)
微信公眾號(hào)

編程獅公眾號(hào)