• laravel lumen 微信支付宝支付扩展


    github地址:

    https://github.com/yansongda/pay

    文档地址:

    https://pay.yansongda.cn/

    扩展小程序红包

    https://pay.weixin.qq.com/wiki/doc/api/tools/cash_coupon.php?chapter=18_2&index=3

     新建一个小程序红包类

    <?php
    
    namespace YansongdaPayGatewaysWechat;
    
    use SymfonyComponentHttpFoundationRequest;
    use YansongdaPayEvents;
    use YansongdaPayExceptionsGatewayException;
    use YansongdaPayExceptionsInvalidArgumentException;
    use YansongdaPayExceptionsInvalidSignException;
    use YansongdaPayGatewaysWechat;
    use YansongdaSupportsCollection;
    
    class MiniappRedpackGateway extends Gateway
    {
        /**
         * Pay an order.
         *
         * @author yansongda <me@yansongda.cn>
         *
         * @param string $endpoint
         *
         * @throws GatewayException
         * @throws InvalidArgumentException
         * @throws InvalidSignException
         */
        public function pay($endpoint, array $payload): Collection
        {
            $payload['wxappid'] = $payload['appid'];
    
            if ('cli' !== php_sapi_name()) {
                $payload['client_ip'] = Request::createFromGlobals()->server->get('SERVER_ADDR');
            }
    
            if (Wechat::MODE_SERVICE === $this->mode) {
                $payload['msgappid'] = $payload['appid'];
            }
    
            unset($payload['appid'], $payload['trade_type'],
                  $payload['notify_url'], $payload['spbill_create_ip']);
    
            $payload['sign'] = Support::generateSign($payload);
    
            Events::dispatch(new EventsPayStarted('Wechat', 'Redpack', $endpoint, $payload));
    
            return Support::requestApi(
                'mmpaymkttransfers/sendminiprogramhb',
                $payload,
                true
            );
        }
    
        /**
         * Get trade type config.
         *
         * @author yansongda <me@yansongda.cn>
         */
        protected function getTradeType(): string
        {
            return '';
        }
    } 

     调用:

    $order = [
        'mch_billno' => '自己生成的交易ID',
        'send_name' => '商户名称',
        'total_amount' => 100,//单位:分
        're_openid' => '用户openId',
        'total_num' => '1',
        'wishing' => '祝福语',
        'act_name' => '活动名称',
        'remark' => '备注',
    ];
    $config = [
        'mch_id' => '商户号',
        'app_id' => '小程序ID',
        'key' => '在微信后台自定义的key',
        'cert_client' => '.../apiclient_cert.pem',
        'cert_key' => '.../apiclient_key.pem',
    ];
    $payWechat = Pay::wechat($config);
    $transfer_res = $payWechat->miniappRedpack($order);
    var_dump($transfer_res);exit();
    

     临时调用,后面单独抽到外部代码

    官方接口:https://pay.weixin.qq.com/wiki/doc/api/tools/miniprogram_hb.php?chapter=13_9 

  • 相关阅读:
    flume复习(二)
    初级3
    桶排序、计数排序、基数排序的介绍
    Hive编程指南读书笔记(1):
    重写、重载、封装、继承和多态
    Int与Integer的区别
    collect_list/collect_set(列转行)
    Group BY
    H指数
    数据倾斜2
  • 原文地址:https://www.cnblogs.com/cxscode/p/14647136.html
Copyright © 2020-2023  润新知