分享微信h5支付源码

本文详细探讨了微信H5支付的原理,并分享了实现这一功能的关键源码,包括请求支付预订单、获取支付签名及调起支付接口等步骤。适合需要集成微信H5支付的开发者参考。
摘要由CSDN通过智能技术生成
<?php
//use Flight;
    /**
     * 微信支付服务器端下单
     * 微信APP支付文档地址:  https://pay.weixin.qq.com/wiki/doc/api/app.php?chapter=8_6
     * 使用示例
     *  构造方法参数
     *      'appid'     =>  //填写微信分配的公众账号ID
     *      'mch_id'    =>  //填写微信支付分配的商户号
     *      'notify_url'=>  //填写微信支付结果回调地址
     *      'key'       =>  //填写微信商户支付密钥
     *  );
     *  统一下单方法
     *  $WechatAppPay = new wechatAppPay($options);
     *  $params['body'] = '商品描述';                   //商品描述
     *  $params['out_trade_no'] = '1217752501201407';   //自定义的订单号,不能重复
     *  $params['total_fee'] = '100';                   //订单金额 只能为整数 单位为分
     *  $params['trade_type'] = 'APP';                  //交易类型 JSAPI | NATIVE |APP | WAP 
     *  $wechatAppPay->unifiedOrder( $params );
     */
    class wechatAppPay
    {   
        //接口API URL前缀
        const API_URL_PREFIX = 'https://api.mch.weixin.qq.com';
        //下单地址URL
        const UNIFIEDORDER_URL = "/pay/unifiedorder";
        //查询订单URL
        const ORDERQUERY_URL = "/pay/orderquery";
        //关闭订单URL
        const CLOSEORDER_URL = "/pay/closeorder";
        //公众账号ID
        private $appid;
        //商户号
        private $mch_id;
        //随机字符串
        private $nonce_str;
        //签名
        private $sign;
        //商品描述
        private $body;
        //商户订单号
        private $out_trade_no;
        //支付总金额
        private $total_fee;
        //终端IP
        private $spbill_create_ip;
        //支付结果回调通知地址
        private $notify_url;
        //交易类型
        private $trade_type;
        //支付密钥
        private $key;
        //证书路径
        private $SSLCERT_PATH;
        private $SSLKEY_PATH;
        //所有参数
        private $params = array();
        public function __construct($appid, $mch_id, $notify_url, $key)
        {
            $this->appid = $appid;
            $this->mch_id = $mch_id;
            $this->notify_url = $notify_url;
            $this->key = $key;
        }
        /**
         * 下单方法
         * @param   $params 下单参数
         */
        public function unifiedOrder( $params ){
            $this->body = $params['body'];
            $this->out_trade_no = $params['out_trade_no'];
            $this->total_fee = $params['total_fee'];
            $this->trade_type = $params['trade_type'];
            $this->scene_info = $params['scene_info'];
            $this->nonce_str = $this->genRandomString();
            $this->spbill_create_ip = $_SERVER['REMOTE_ADDR'];
            $this->params['appid'] = $this->appid;
            $this->params['mch_id'] = $this->mch_id;
            $this->params['nonce_str'] = $this->nonce_str;
            $this->params['body'] = $this->body;
            $this->params['out_trade_no'] = $this->out_trade_no;
            $this->params['total_fee'] = $this->total_fee;
            $this->params['spbill_create_ip'] = $this->spbill_create_ip;
            $this->params['notify_url'] = $
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值