多应用+插件架构,代码干净,二开方便,首家独创一键云编译技术,文档视频完善,免费商用码云13.8K 广告
## **如何接入呆错支付** 在开发自己的应用需要使用到收款时,只需按以下两步即可快速完成接入。 #### **付款选项(前端)** 在安装了呆错支付插件后,需要使用付款的任意模板位置调用支付平台列表函数(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'); } ```