## **如何接入呆錯支付**
在開發自己的應用需要使用到收款時,只需按以下兩步即可快速完成接入。
#### **付款選項(前端)**
在安裝了呆錯支付插件后,需要使用付款的任意模板位置調用支付平臺列表函數(payPlatForms)生成付款選項。實例如下
```
<form action="{:DcUrl('pay/index/save')}" method="post">
<div class="form-group">
<label for="score_rmb"><strong>打賞金額</strong></label>
<input class="form-control form-control-sm" name="score_rmb" id="score_rmb" type="text" value="1" required autocomplete="off">
</div>
<div class="form-text">
<label for="score_type"><strong>支付方式</strong></label>
</div>
{foreach name=":payPlatForms()" id="platForm"}
<div class="custom-control custom-radio mb-3">
<input class="custom-control-input" name="score_type" id="score_type_{$key}" type="radio" value="{$platForm}" {if $key eq 0}checked{/if}>
<label class="custom-control-label" for="score_type_{$key}">{:lang('pay_'.$platForm)}</label>
</div>
{/foreach}
<div class="form-group">
<button class="btn btn-purple" type="submit">我要打賞</button>
</div>
</form>
```
#### **發起支付(后端)**
在插件應用的控制器操作單元里接收到表單的金額與付款平臺后,通過paySubmit函數發起支付(根據不同的場景調用對應支付平臺的付款生成接口)。實例如下
```
public function save()
{
$post = [];
$post['pay_platform'] = input('request.score_type/s', 'empty');//支付平臺
$post['pay_price'] = sprintf("%.2f",input('request.score_rmb/s', 1));//單價
$post['pay_quantity'] = 1;//數量
$post['notify_url'] = $this->site['domain'].DcUrl('pay/'.$post['pay_platform'].'/notify');//異步通知
$post['return_url'] = $this->site['domain'].DcUrl('pay/index/notify');//同步通知
$post['pay_info_id'] = 1;//內容ID
$post['pay_user_id'] = $this->site['user']['user_id'];//用戶ID
$post['pay_total_fee'] = $post['pay_price']*$post['pay_quantity'];//總價
$post['pay_module'] = 'pay';//應用名
$post['pay_controll'] = 'index';//模塊名
$post['pay_action'] = 'save';//操作名
$post['pay_scene'] = 'pc';//支付場景
$post['pay_name'] = '任性打賞('.config('common.site_name').')';//商品描述
//是否手機支付
if($this->request->isMobile()){
$post['pay_scene'] = 'wap';
}
//發起支付
if($result = paySubmit($post)){
return $result;
}
//支付失敗
$this->error(config('daicuo.error'), 'pay/index/index');
}
```