码迷,mamicode.com
首页 > 微信 > 详细

laravel lumen 微信支付宝支付扩展

时间:2021-04-13 12:00:14      阅读:0      评论:0      收藏:0      [点我收藏+]

标签:service   doc   ring   new   exce   red   poi   商户   定义   

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 Yansongda\Pay\Gateways\Wechat;

use Symfony\Component\HttpFoundation\Request;
use Yansongda\Pay\Events;
use Yansongda\Pay\Exceptions\GatewayException;
use Yansongda\Pay\Exceptions\InvalidArgumentException;
use Yansongda\Pay\Exceptions\InvalidSignException;
use Yansongda\Pay\Gateways\Wechat;
use Yansongda\Supports\Collection;

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 Events\PayStarted(‘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();

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

 

laravel lumen 微信支付宝支付扩展

标签:service   doc   ring   new   exce   red   poi   商户   定义   

原文地址:https://www.cnblogs.com/cxscode/p/14647136.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!