word php 导出html css_PHP实现个人支付宝支付开发(五)

点击蓝字65f8ae79534aaa3c1b8cdfb4c6720195.png关注我们!每天获取最新的编程小知识!

d588418aaf450b1b3103425ef5778bb3.gif

源 / php中文网      源 / www.php.cn

在前面的文章《PHP实现个人支付宝支付开发(四)》中,我们为大家介绍了在网站上安装使用支付宝接口文件的流程。

6aa0d3171ce3ac8dc55e9abf5d0e6faa.png

(视频版请点击本文末尾左下角:

下面我们继续结合之前的案例源码,给大家介绍PHP实现个人支付宝支付开发功能的相关内容。

codepay_config.php文件是码支付的配置文件。前文中的码支付ID和通信秘钥就在如下图中的位置。

4e20db3df041e302b21cf6ee268d37c3.png

前文中创建的数据表如下。

1e245e48136223ea3592e8bbb42de289.png

案例中index.html前台文件:

<html>

<head>

    <meta charset="utf-8">

    <meta http-equiv="Access-Control-Allow-Origin" content="*">

    <title>信息title>

    <link rel="stylesheet" href="__INDEX__/layui/css/layui.css" media="all">

head>

<body>

<ul class="layui-nav" style="border-radius:0px;" lay-filter="">

    <li class="layui-nav-item"><a href="">最新活动a>li>

    <li class="layui-nav-item "><a href="">产品a>li>

    <li class="layui-nav-item"><a href="">大数据a>li>

    <li class="layui-nav-item"><a href="">社区a>li>

ul>

<div class="layui-carousel" id="test1">

    <div carousel-item>

        <div>条目1div>

        <div>条目2div>

        <div>条目3div>

        <div>条目4div>

        <div>条目5div>

    div>

div>

<div class="layui-fluid">

    <div class="layui-row layui-col-space15">

        <div class="layui-col-md12">

            <div class="layui-card">

                <div class="layui-card-header">网站设置div>

                <div class="layui-card-body" pad15>

                    <div class="layui-form" lay-filter="text">

                        <div class="layui-form-item">

                            <label class="layui-form-label">信息名label>

                            <div class="layui-input-block">

                                <input type="text" name="provenance_url" id="provenance_url"

                                       placeholder="信息名" value="" class="layui-input">

                            div>

                        div>

                        <div class="layui-form-item">

                            <label class="layui-form-label">信息描述label>

                            <div class="layui-input-inline" style="width: 85%;">

                                <textarea name="provenance_desc" id="provenance_desc" lay-verify="required"

                                          placeholder="请仔细填写描述" class="layui-textarea">textarea>

                            div>

                            <div class="layui-form-mid layui-word-aux">

                                <span class="x-red" style="color: red">*必填span>

                            div>

                        div>

                        <div class="layui-form-item">

                            <label class="layui-form-label">联系方式label>

                            <div class="layui-input-inline">

                                <input type="text" name="user_qq" id="user_qq"

                                       lay-verify="required" placeholder="要求填写QQ联系方式" class="layui-input">

                            div>

                            <div class="layui-form-mid layui-word-aux">

                                <span class="x-red" style="color: red">*必填span>

                            div>

                        div>

                        <div class="layui-form-item">

                            <label class="layui-form-label">信息图片label>

                            <div class="layui-input-block">

                                <button type="button" class="layui-btn" id="test2">图片上传button>

                                <div class="layui-upload-list" id="thumbnail">div>

                            div>

                        div>

                        <div class="layui-form-item">

                            <div class="layui-input-block">

                                <button class="layui-btn" lay-submit lay-filter="test">保存button>

                            div>

                        div>

                    div>

                div>

            div>

        div>

    div>

div>

<div class="layui-fluid" id="order" style="display: none">

    <div class="layui-row layui-col-space15">

        <div class="layui-col-md12">

            <div class="layui-card">

                <div class="layui-card-header">确认订单div>

                <div class="layui-card-body" pad15>

                    <div class="layui-form" lay-filter="text">

                        <div class="layui-form-item">

                            <label class="layui-form-label">信息名label>

                            <div class="layui-input-block">

                                <input type="text" name="provenance_url" id="url"

                                       placeholder="信息名" value="" class="layui-input"  disabled="true">

                            div>

                        div>

                        <div class="layui-form-item">

                            <label class="layui-form-label">信息描述label>

                            <div class="layui-input-inline">

                                <textarea name="provenance_desc" id="desc" lay-verify="required"

                                          placeholder="请仔细填写描述" class="layui-textarea"   disabled="true">textarea>

                            div>

                        div>

                        <div class="layui-form-item">

                            <label class="layui-form-label">联系方式label>

                            <div class="layui-input-inline">

                                <input type="text" name="user_qq" id="qq"

                                       lay-verify="required" placeholder="要求填写QQ联系方式"   disabled="true" class="layui-input">

                            div>

                        div>

                        <div class="layui-form-item">

                            <label class="layui-form-label">金额label>

                            <div class="layui-input-inline">

                                <input type="text" name="price" id="price"

                                       lay-verify="required" placeholder="要求填写QQ联系方式" value=""   disabled="true" class="layui-input">

                            div>

                        div>

                        <div class="layui-form-item">

                            <label class="layui-form-label">支付方式label>

                            <div class="layui-input-block">

                                <input type="radio" name="type" value="1" title="支付宝">

                                <img src="static/index/images/Alipay.png">

                                <input type="radio" name="type" value="2" title="微信">

                                <img src="static/index/images/WeChat.png">

                            div>

                        div>

                        <div class="layui-form-item">

                            <div class="layui-input-block">

                                <button class="layui-btn" lay-submit lay-filter="pay">确定支付button>

                            div>

                        div>

                    div>

                div>

            div>

        div>

    div>

div>

<script src="__INDEX__/layui/layui.js">script>

<script>

    //注意:导航 依赖 element 模块,否则无法进行功能性操作

    layui.use('element', function () {

        var element = layui.element;

        //…

    });

    layui.use('carousel', function () {

        var carousel = layui.carousel;

        //建造实例

        carousel.render({

            elem: '#test1'

            , width: '100%' //设置容器宽度

            , arrow: 'always' //始终显示箭头

            //,anim: 'updown' //切换动画方式

        });

    });

    layui.use(['form', 'upload'], function () {

        var form = layui.form,

            $ = layui.jquery,

            upload = layui.upload;

        upload.render({

            elem: '#test2',

            url: "index.php/index/upload",

            multiple: true,

            before: function (obj) {

                //预读本地文件示例,不支持ie8

                obj.preview(function (index, file, result) {

                    $('#thumbnail').append('<img src="' + result + '" alt="' + file.name + '" class="layui-upload-img">')

                });

            },

            done: function (res) {

                //上传完毕

                $('#thumbnail').append('<input type="hidden" name="file[]" id="file" value="' + res.data + '" />')

            }

        });

        form.on('submit(test)', function (data) {

            console.log(data.field);

            $.ajax({

                url: "index.php/index/order",

                dataType: "json",

                data: data.field,

                success: function (res) {

                    console.log(res)

                    if (res.code >= 1) {

                        layer.alert(res.msg, {icon: 5})

                    } else {

                        $('#url').val(res.data['provenance_url'])

                        $('#desc').val(res.data['provenance_desc'])

                        $('#qq').val(res.data['user_qq'])

                        $('#price').val(res.price)

                        layer.open({

                            type: 1 //此处以iframe举例

                            , title: '提交BUG'

                            , area: ['700px', '650px']

                            , maxmin: true

                            , btnAlign: 'c'

                            , shade: false

                            , content: $('#order')

                        });

                    }

                }

            });

        })

        form.on('submit(pay)',function (data) {

            $.post('codepay/codepay.php',{

                'type':data.field.type,

                'price':data.field.price,

                'user':'admin'

            },function (data) {

                console.log(data)

                   layer.open({

                    type: 1 //此处以iframe举例

                    , title: '提交BUG'

                    , area: ['700px', '650px']

                    , maxmin: true

                    , btnAlign: 'c'

                    , shade: false

                    , content: data

                });

            })

        })

    })

script>

注:前台获取的三个信息'type', 'price'和'user'必须要提交给接口文件codepay.php。

57f2f83b4a8f8ae504ffd7bcd0e22c68.png

控制器中的index.php文件:

/**

 * Created by PhpStorm.

 * User: win7

 * Date: 2019/1/2

 * Time: 9:32

 */

namespace app\index\controller;

use think\Controller;

use \think\facade\Request;

use think\facade\Session;

class Index extends Controller

{

    public function index()

    {

        return $this->fetch();

    }

    public function order()

    {

        $data = Request::param();

        if(empty($data['file'])){

            return json(['code'=>1,'msg'=>'请添加车牌相关图片']);

        }

        $pic_count = count($data['file']);

        if ($pic_count > 1){

            return json(['code'=>0,'msg'=>'订单生成','price'=>15,'data'=>$data]);

        }else{

            return json(['code'=>0,'msg'=>'订单生成','price'=>0.1,'data'=>$data]);

        }

    }

    public function upload()

    {

        // 获取到上传的图片

        $file = request()->file('file');

        // 移动到框架应用根目录/uploads/ 目录下

        if ($info = $file->validate(['ext' => 'jpg,jpeg,png,gif'])->move('upload')) {

            //客户端要求返回的必须是JSON格式数据,默认没有加上上传目录,需要手工添加一下

            return json([1, '上传成功!', 'data' => ['/upload/' . $info->getSaveName()]]);

        } else {

            //处理出错信息,其实客户端也会处理的,可省略

            return $file->getError();

        }

    }

}

因为我们只写了一个小案例,这里的订单内容也就很简单,当上传的图片大于1时则需要付15元,小于1时,只需付0.1元。

本篇文章就是关于PHP实现个人支付宝支付开发的相关介绍,其实也非常简单易懂,在后续的文章中,我们再继续为大家讲解相关知识内容。

fbf41cd9b9525c6b0b79259ecdccf6c0.gif

-END-

声明:本文选自「 php中文网 」,搜索「 phpcnnew 」即可关注!

83a2d84062f47a55c4f747047e695771.pngb9bdba790a805b26aef373aba287471c.gif

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值