创建微信卡券 php

这篇博客介绍了如何使用PHP创建微信卡券,包括设置卡券类型、商户名称、标题、颜色、提示信息、客服电话、使用须知以及有效期等关键参数。通过couponDo函数处理POST请求的数据,并调用微信API来生成卡券。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

public function createCoupon()
    {
        $data['card_type'] = $this->input->post_get('card_type');//代金券、兑换券、优惠券、折扣券
        $data['brand_name'] = $this->input->post_get('brand_name');//商户名字
        $data['title'] = $this->input->post_get('title');//卡券名
        $data['color'] = $this->input->post_get('color');//卡券颜色
        $data['notice'] = $this->input->post_get('notice');//操作提示
        $data['service_phone'] = $this->input->post_get('service_phone');//客服电话
        $data['description'] = $this->input->post_get('description');//使用须知
        $data['begin_timestamp'] = $this->input->post_get('begin_timestamp');//开始时间
        $data['end_timestamp'] = $this->input->post_get('end_timestamp');//结束时间
        $data['fixed_term'] = $this->input->post_get('fixed_term');//表示自领取后多少天内有效
        $data['location_id_list'] = $this->input->post_get('location_id_list');//门店id
//        $data['use_limit'] = $this->input->post_get('use_limit');//每人可领券的数量限制,不填写默认为50
//        $data['get_limit'] = $this->input->post_get('get_limit');//每人可核销的数量限制,不填写默认为50
//        $data['can_share'] = $this->input->post_get('can_share');//卡券领取页面是否可分享
//        $data['can_give_friend'] = $this->input->post_get('can_give_friend');//卡券是否可转赠
//        $data['quantity'] = $this->input->post_get('quantity');//库存多少张
        $res = $this->couponDo($data);
        var_dump($res);
    }

public function couponDo($data)

    {
        $array = array(
            "card" => array(
                "card_type" => $data['card_type'],

                 strtolower($data['card_type']) => array(   //用传过来的卡券类型当键  必须是小写

                        "base_info" => array(

                        "logo_url" => "",   //已经上传过的logo  url

                           "code_type" => 'CODE_TYPE_QRCODE',

                        "brand_name" => $data['brand_name'],
                        "title" => $data['title'],
                        "color" => $data['color'],
                        "notice" => $data['notice'],
                        "description" => $data['description'],
                        "sku" => array("quantity" => 0),  //自定义code码为0
                        "date_info" => array(
                            "type" => 'DATE_TYPE_FIX_TIME_RANGE',
                            "begin_timestamp" => $data['begin_timestamp'],
                            "end_timestamp" => $data['end_timestamp'],
                            "fixed_term" => $data['fixed_term'],
                            "fixed_begin_term" => 0
                        ),
                        "service_phone" => $data['service_phone'],
                        "location_id_list" => [$data['location_id_list']],
                        "use_limit" => 1,
                        "get_limit" => 1,
                        "use_custom_code" => true,   //自定义code码为true
                        "bind_openid" => false,
                        "can_share" => true,
                        "can_give_friend" => true,
                        "get_custom_code_mode" => "GET_CUSTOM_CODE_MODE_DEPOSIT"   //自定义code码
                    ),
//                    "least_cost" => 0,  //满多少可用  单位 分
//                    "reduce_cost" => 50000,  //减多少
                )
            )
        );
        $url = "https://api.weixin.qq.com/card/create?access_token=" . $this->token;
        return curl_post($url, json_encode($array, JSON_UNESCAPED_UNICODE));
    }
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值