Thinkphp 5.1 微信小程序微信支付

本文是新手对Thinkphp 5.1框架下微信小程序支付的实践记录,包括Pay.php和WeixinPay.php的使用,旨在帮助初学者理解支付流程。

刚学习thinkPHP,小白一位,记录一下,大神们不要笑!

Pay.php

<?php

namespace app\index\controller;

use think\exception\HttpResponseException;
use think\Response;
use lib\WeixinPay;

class Pay {
    public function payfee()
    {
        $appid='';
        $openid= input('openid');
        $mch_id='';
        $key='';
        $out_trade_no = $mch_id. time();
        $total_fee = input('total_fee');
        if($total_fee) {
            $body = "小天才电话手表";
            $total_fee = floatval($total_fee*100);
        }

        $weixinpay = new WeixinPay($appid,$openid,$mch_id,$key,$out_trade_no,$body,$total_fee);
        $return=$weixinpay->pay();


        if($return){
            // 这里返回数据
            $this->responseSuccess($return);
        }else{
            // 这里返回错误码及错误信息,供客户端调用
            $this->responseErro(400401,'没有找到该用户');
        }
    }
    public function notify ()
    {
        $postXml = $GLOBALS["HTTP_RAW_POST_DATA"]; //接收微信参数
        if (empty($postXml)) {
            return false;
        }
       //将xml格式转换成数组
        function xmlToArray($xml) {
            //禁止引用外部xml实体
            libxml_disable_entity_loader(true);
            $xmlstring = simplexml_load_string($xml, 'SimpleXMLElement', LIBXML_NOCDATA);
            $val = json_decode(json_encode($xmlstring), true);
            return $val;
        }
        $attr = xmlToArray($postXml);
        $total_fee = $attr[total_fee];
        $open_id = $attr[openid];
        $out_trade_no = $attr[out_trade_no];
        $time = 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值