.net 微信会员卡接口

创建接口 

protected void Page_Load(object sender, EventArgs e)
        {
            taosoftsweixin.WX.Access_token at = taosoftsweixin.WX.WeiXinHelper.GetAccess_token();
            string url_Menu_Create = "https://api.weixin.qq.com/card/create?access_token=" + at.access_token;


            string postData = createMenuDate();
            string result = PostWebRequest(url_Menu_Create, postData);

        }
        public string PostWebRequest(string postUrl, string paramData)
        {
            string ret = string.Empty;
            try
            {
                byte[] byteArray = Encoding.UTF8.GetBytes(paramData); //转化
                HttpWebRequest webReq = (HttpWebRequest)WebRequest.Create(new Uri(postUrl));
                webReq.Method = "POST";
                webReq.ContentType = "application/json";

                webReq.ContentLength = byteArray.Length;
                Stream newStream = webReq.GetRequestStream();
                newStream.Write(byteArray, 0, byteArray.Length);//写入参数
                newStream.Close();
                HttpWebResponse response = (HttpWebResponse)webReq.GetResponse();
                StreamReader sr = new StreamReader(response.GetResponseStream(), Encoding.UTF8);
                ret = sr.ReadToEnd();
                sr.Close();
                response.Close();
                newStream.Close();
            }
            catch (Exception ex)
            {

            }
            return ret;

        }
        public string createMenuDate()
        {
            string postData = "{";
            postData += "\"card\": {";
            postData += "\"card_type\": \"MEMBER_CARD\",";
            postData += "\"member_card\": {";
            postData += "\"background_pic_url\": \"https://mmbiz.qlogo.cn/mmbiz/\",";
            postData += "\"base_info\": {";
            postData += "\"logo_url\": \"https://mmbiz.qlogo.cn/mmbiz_jpg/\",";
            postData += "\"brand_name\": \"XXX\",";
            postData += "\"code_type\": \"CODE_TYPE_BARCODE\",";
            postData += "\"title\": \"会员卡\",";
            postData += "\"color\": \"Color010\",";
            postData += "\"notice\": \"使用时向服务员出示此会员卡\",";
            postData += "\"service_phone\": \"0335-5300544\",";
            postData += "\"description\": \"不可与其他优惠同享\",";
            postData += "\"date_info\": {";
            postData += "\"type\": \"DATE_TYPE_PERMANENT\"";
            postData += "},";
            postData += "\"sku\": {";
            postData += "\"quantity\": 100000000";
            postData += "},";
            postData += "\"get_limit\": 1,";

            postData += "\"use_custom_code\": false,";
            postData += "\"can_give_friend\": true,";
            postData += "\"custom_url_name\": \"会员卡中心\",";
            postData += "\"custom_url\": \"http://xxxx\"";
            postData += "},";
            postData += "\"supply_bonus\": false,";
            postData += "\"supply_balance\": false,";
            postData += "\"prerogative\": \"会员专用\",";
            postData += "\"wx_activate\": true,";
            postData += "\"wx_activate_after_submit\": true,";
            postData += "\"wx_activate_after_submit_url\": \"http://xxxx\"";
            postData += "}";
            postData += "}";
            postData += "}";
            return postData;
        }

    }
}
必填项目

protected void Page_Load(object sender, EventArgs e)
        {
            taosoftsweixin.WX.Access_token at = taosoftsweixin.WX.WeiXinHelper.GetAccess_token();
            string url_Menu_Create = "https://api.weixin.qq.com/card/membercard/activateuserform/set?access_token=" + at.access_token;


            string postData = createMenuDate();
            string result = PostWebRequest(url_Menu_Create, postData);

        }
        public string PostWebRequest(string postUrl, string paramData)
        {
            string ret = string.Empty;
            try
            {
                byte[] byteArray = Encoding.UTF8.GetBytes(paramData); //转化
                HttpWebRequest webReq = (HttpWebRequest)WebRequest.Create(new Uri(postUrl));
                webReq.Method = "POST";
                webReq.ContentType = "application/json";

                webReq.ContentLength = byteArray.Length;
                Stream newStream = webReq.GetRequestStream();
                newStream.Write(byteArray, 0, byteArray.Length);//写入参数
                newStream.Close();
                HttpWebResponse response = (HttpWebResponse)webReq.GetResponse();
                StreamReader sr = new StreamReader(response.GetResponseStream(), Encoding.UTF8);
                ret = sr.ReadToEnd();
                sr.Close();
                response.Close();
                newStream.Close();
            }
            catch (Exception ex)
            {

            }
            return ret;

        }
        public string createMenuDate()
        {
            string postData = "{";

            postData += "\"card_id\": \"XXX",";
            postData += "\"required_form\": {";
            postData += "\"can_modify\":false,";

            postData += "\"common_field_id_list\": [";
            postData += "\"USER_FORM_INFO_FLAG_NAME\",";
            postData += "\"USER_FORM_INFO_FLAG_MOBILE\"";
            postData += "]";
            postData += "}";
            postData += "}";
            return postData;
        }

    }
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值