微信卡券之创建会员卡(自定义code(卡号)型 -》指定code)

一. 会员卡分为:

  1.     自定义code(卡号):(自定义code分为导入code 型 指定code)
  2.     非自定义code(卡号)
  3.     流程
    1. 微信公众平台 开通微信卡券功能
    2. 创建会员卡
    3. 分配会员卡
    4. 领取并激活会员卡
  4. # 创建会员卡 此创建为在微信公众平台创建一类卡
        public function createCard($value='')
        {
            $access_token = $this->getAccessToken();
            $data = $this->request->param();
    
            $url = "https://api.weixin.qq.com/card/create?access_token=".$access_token['access_token'];
            $str = '{
                    "card": {
                        "card_type": "MEMBER_CARD",
                        "member_card": {
                            "background_pic_url":"https://mmbiz.qlogo.cn/mmbiz_jpg/dpoqAWiPAut0iaNkgH9csTRrD3lJGMrHU1Z8LpORzbev51FaiaCu8d13uoBLzF2CXiatUEPukaENUw/0",
                            "base_info": {
                                "logo_url": "http://dd.cc.com/static/images/20190812134157.jpg",
                                "brand_name": "某某超市",
                                "code_type": "CODE_TYPE_BARCODE",
                                "title": "会员卡",
                                "color": "Color010",
                                "notice": "使用时向服务员出示此卡",
                                "service_phone": "0438-55555555",
                                "description": "不可与其他优惠同享",
                                "date_info": {
                                    "type": "DATE_TYPE_PERMANENT"
                                },
                                "sku": {
                                    "quantity": 100000000
                                },
                                "get_limit": 1,
                                "use_custom_code": true
                            },
                            "supply_bonus": false,
                            "supply_balance": false,
                            "prerogative": "超市会员卡",
                            "auto_activate": true,
                            "custom_field1": {
                                "name": "积分",
                                "url": "http://dd.cc.com/portal/card/bonus"
                            },
                            "custom_field2": {
                                "name": "等级",
                                "url": "http://dd.cc.com/portal/card/myCards"
                            },
                            "custom_field3": {
                                "name": "优惠",
                                "url": "http://dd.cc.com/portal/card/activity"
                            },
                            "activate_url": "",
                            "custom_cell1": {
                                "name": "会员信息",
                                "url": "http://dd.cc.com/portal/card/index"
                            },
                            "custom_cell2": {
                                "name": "会员等级",
                                "url": "http://dd.cc.com/portal/card/myCards"
                            },
                            "discount": "2",
                            "wx_activate": true,
                            "wx_activate_after_submit": true,
                            "wx_activate_after_submit_url": "http://dd.cc.com/portal/card/myCard"
                        }
                    }
                }';
            $res = json_decode(cmf_curl_post($url,$str),true);
    
            if ($res['errcode']==0) {
                Db::name('card_type')->insert(['card_id'=>$res['card_id'],'create_time'=>time()]);
                $this->success("创建成功!");
            } else {
                $this->error("创建失败!");
            }
        }

     

    #1、获取access_token access_token 的有效时间是7200s,故可以采用文件存储的方法进行保存,避免多次请求;
         public function getAccessToken(){
            $url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=wx12345678&secret=f45d454d7a87dd";
            $res = cmf_curl_get($url);
            $res = json_decode($res,1);
            return $res; 
            
        }
    /**
     * curl get 请求 放在cmf公共方法中
     * @param $url
     * @return mixed
     */
    function cmf_curl_get($url)
    {
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_FAILONERROR, true);
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
        curl_setopt($ch, CURLOPT_AUTOREFERER, true);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_TIMEOUT, 5);
        $SSL = substr($url, 0, 8) == "https://" ? true : false;
        if ($SSL) {
            curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // 信任任何证书
            curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2); // 检查证书中是否设置域名
        }
        $content = curl_exec($ch);
        curl_close($ch);
        return $content;
    }
    

    card表:

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值