在会员领取了会员卡之后需要做 一个跳转性激活,模式请看下图:

在创建会员卡的时候需要配置下这个参数的值:

memberActivate.aspx页面代码如下:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="memberActivate.aspx.cs" Inherits="ChainStock.mobile.member.memberActivate" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<title>激活会员卡</title>
<script src="js/jquery.min.js" type="text/javascript"></script>
<%--<script src="scripts/bootstrap.min.js" type="text/javascript"></script>--%>
<link href="css/bootstrap.min.css" rel="stylesheet" />
<style type="text/css">
.no-padding {
padding: 0px;
} .no-margin {
margin: 0px;
} .btn_active {
background-color: #019a01;
width: %;
padding: 7px 0px;
color: white;
border: 1px solid #019a01;
} .btn_return {
background-color: #f8f8f8;
width: %;
padding: 7px 0px;
color: black;
border: 1px solid #e6e6e6;
}
</style>
<script type="text/javascript">
$(function () {
$(".btn_return").bind("click", function () {
event.preventDefault();
window.history.back();
})
});
</script>
</head>
<body style="background-color: #f2f2f2;" class="no-padding no-margin">
<form id="form1" runat="server">
<div class="container no-padding">
<br />
<div class="col-xs-12">
<div class="col-xs-12">
<label>请确定以下信息:</label> </div>
</div>
<div class="clearfix"></div>
<br />
<div style="background-color: white; padding: 30px 0px; border-bottom: 1px solid #dbdbdb; border-top: 1px solid #dbdbdb;">
<div class="col-xs-12">
<div class="col-xs-3">
用户名
</div>
<div class="col-xs-9 no-padding text-left" id="divMemName" runat="server"></div>
<div class="clearfix"></div>
</div>
<div class="col-xs-12" style="padding-top: 10px;">
<div class="col-xs-3">
手机号
</div>
<div class="col-xs-9 no-padding text-left" id="divMemMobile" runat="server">
</div>
<div class="clearfix"></div>
</div>
<div class="clearfix"></div>
</div>
<br /> <div class="col-xs-12 no-padding">
<div class="col-xs-12 text-center">
<input type="button" class="btn btn-sm btn_active" value="激活会员卡" id="btnActiveMem" />
<input type="hidden" id="hd_MemMobile" value="" runat="server" />
<input type="hidden" id="hd_CardCode" value="" runat="server" />
<input type="hidden" id="hd_CardId" value="" runat="server" />
</div> <div class="col-xs-12 text-center">
<br />
<input type="button" class="btn btn-sm btn_return" value="返 回" />
</div>
<div class="col-xs-12 ">
<h6 style="color: red;">注:激活后不可修改上面的信息</h6>
</div> <div class="clearfix"></div>
</div>
</div>
</form> <script type="text/javascript" src="scripts/jquery-2.1.4.min.js"></script>
<script type="text/javascript" src="http://res.wx.qq.com/open/js/jweixin-1.4.0.js"></script>
<script type="text/javascript">
$(function () {
//激活会员卡
$("#btnActiveMem").click(function () {
$.ajax({
type: "GET",
url: "../../Service/AjaxService.ashx?Method=Wx_ActivateCard",
data: {
memMobile: $("#hd_MemMobile").val(),
cardCode: $("#hd_CardCode").val(),
cardId: $("#hd_CardId").val()
},
dataType: "text",
success: function (result) {
if (result != null && result != "") {
switch (result) {
case "":
alert("系统错误,请稍后再试");
break;
case "-1":
alert("系统异常,请联系管理员");
break;
case "-2":
alert("您还不是会员,激活失败");
break;
default:
alert("激活成功");
wx.closeWindow();//这一步就是会员激活了之后就自动跳转到会员卡详细页面
}
}
}
});
});
})
</script>
</body>
</html>

后台代码:

using Chain.Wechat;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Data;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls; namespace ChainStock.mobile.member
{
public partial class memberActivate : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{ BindData(); }
void BindData()
{
string code = "";
string openid = "";
string access_token = "";
string strEncrypt_code = "";
string tick_code = "";
string strActivate_ticket = "";
string cardId = ""; try
{
if (!string.IsNullOrEmpty(Request.QueryString["encrypt_code"]))
{
strEncrypt_code = Request.QueryString["encrypt_code"].ToString();
}
if (!string.IsNullOrEmpty(Request.QueryString["card_id"]))
{
cardId = Request.QueryString["card_id"].ToString();
hd_CardId.Value = cardId;
}
string getAuthorize = GetAuthorize();
if (getAuthorize != "")
{
getAuthorize = "[" + getAuthorize + "]"; Newtonsoft.Json.Linq.JArray javascript = (Newtonsoft.Json.Linq.JArray)JsonConvert.DeserializeObject(getAuthorize);
Newtonsoft.Json.Linq.JObject obj = (Newtonsoft.Json.Linq.JObject)javascript[]; if (obj["access_token"] != null && obj["access_token"].ToString() != "")
{
access_token = obj["access_token"].ToString();//用户OpenID
}
}
if (!string.IsNullOrEmpty(access_token))
{
if (!string.IsNullOrEmpty(Request.QueryString["encrypt_code"]))
{
strEncrypt_code = Request.QueryString["encrypt_code"].ToString();
string postUrl = "https://api.weixin.qq.com/card/code/decrypt?access_token=" + access_token;
string postDate = "{\"encrypt_code\":\"" + strEncrypt_code + "\"}"; string strResult = PostWebRequest(postUrl, postDate);
strResult = "[" + strResult + "]";
Newtonsoft.Json.Linq.JArray codeArray = (Newtonsoft.Json.Linq.JArray)JsonConvert.DeserializeObject(strResult);
Newtonsoft.Json.Linq.JObject objResult = (Newtonsoft.Json.Linq.JObject)codeArray[];
if (objResult["errmsg"].ToString() == "ok")
{
code = objResult["code"].ToString();
hd_CardCode.Value = code;
if (!string.IsNullOrEmpty(Request["activate_ticket"]))
{
strActivate_ticket = Request["activate_ticket"].ToString();
} if (!string.IsNullOrEmpty(strActivate_ticket))
{
string ticketPostUrl = "https://api.weixin.qq.com/card/membercard/activatetempinfo/get?access_token=" + access_token;
string ticketPostData = "{ \"activate_ticket\" : \"" + strActivate_ticket + "\"}";
string userInfoResult = PostWebRequest(ticketPostUrl, ticketPostData);
userInfoResult = "[" + userInfoResult + "]"; Newtonsoft.Json.Linq.JArray userInfoArray = (Newtonsoft.Json.Linq.JArray)JsonConvert.DeserializeObject(userInfoResult);
Newtonsoft.Json.Linq.JObject objUserInfo = (Newtonsoft.Json.Linq.JObject)userInfoArray[];
if (objUserInfo["errmsg"].ToString() == "ok")
{
string userMobile = objUserInfo["info"]["common_field_list"][]["value"].ToString();
string userName = objUserInfo["info"]["common_field_list"][]["value"].ToString();
if (!string.IsNullOrEmpty(userMobile))
{
hd_MemMobile.Value = userMobile;
divMemMobile.InnerText = userMobile;
divMemName.InnerText = userName;
}
}
}
}
}
}
}
catch (Exception ex)
{
PubFunction.LogError("微信激活会员授权异常:" + ex);
}
} //通过code换取网页授权access_token
public string GetAuthorize()
{
//PubFunction.curParameter.strWeiXinAppID = "wxcb014df3a2583811";
//PubFunction.curParameter.strWeiXinAppSecret = "1fb18946950b112cd79103a7b1f9249b";
if (PubFunction.curParameter.strWeiXinAppID != null && PubFunction.curParameter.strWeiXinAppSecret != null)
{
string templateUrl = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid={0}&secret={1}";
templateUrl = string.Format(templateUrl, PubFunction.curParameter.strWeiXinAppID, PubFunction.curParameter.strWeiXinAppSecret);
HttpRequestHelper hrh = new HttpRequestHelper();
return hrh.Reqeust(templateUrl);
}
else
{
return "";
}
} /// <summary>
/// 发送Post请求到微信端
/// </summary>
/// <param name="postUrl">请求的路径</param>
/// <param name="paramData">发送的数据</param>
/// <returns></returns>
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, , 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)
{
PubFunction.LogError(ex);
}
return ret; }
}
}

激活时我使用了一般处理程序来激活的代码如下:这个是根据我的系统做了一个判断,是我系统中的会员才能激活,否则不能激活

#region 跳转式激活会员卡 参考:https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1451025283   6.6.2
public void Wx_ActivateCard()
{
int flag = ;
string access_token = "";
try
{
string strMemMobile = !string.IsNullOrEmpty(Request["memMobile"]) ? Request["memMobile"].ToString() : "";//手机号
string strCardCode = !string.IsNullOrEmpty(Request["cardCode"]) ? Request["cardCode"].ToString() : "";//卡Code
string strCardId = !string.IsNullOrEmpty(Request["cardId"]) ? Request["cardId"].ToString() : "";//卡ID
if (!string.IsNullOrEmpty(strMemMobile))
{
Chain.BLL.Mem bllMem = new Chain.BLL.Mem();
DataTable dtMem = bllMem.GetList(" MemMobile='" + strMemMobile + "' ").Tables[];
if (dtMem.Rows.Count > )//执行激活(只有系统中的会员才能激活)
{
string getAuthorize = GetAuthorize();
if (getAuthorize != "")
{
getAuthorize = "[" + getAuthorize + "]"; Newtonsoft.Json.Linq.JArray javascript = (Newtonsoft.Json.Linq.JArray)JsonConvert.DeserializeObject(getAuthorize);
Newtonsoft.Json.Linq.JObject obj = (Newtonsoft.Json.Linq.JObject)javascript[]; if (obj["access_token"] != null && obj["access_token"].ToString() != "")
{
access_token = obj["access_token"].ToString();
}
if (!string.IsNullOrEmpty(strCardCode) && !string.IsNullOrEmpty(strCardId))
{
string postData = "{";
postData += "\"membership_number\": \"" + strMemMobile + "\",";
postData += "\"code\": \"" + strCardCode + "\",";
postData += "\"card_id\": \"" + strCardId + "\"";
postData += "}";
string postUrl = "https://api.weixin.qq.com/card/membercard/activate?access_token=" + access_token;
string result = PostWebRequest(postUrl, postData); if (!string.IsNullOrEmpty(result))
{
result = "[" + result + "]";
Newtonsoft.Json.Linq.JArray cardResult = (Newtonsoft.Json.Linq.JArray)JsonConvert.DeserializeObject(result);
Newtonsoft.Json.Linq.JObject cardObj = (Newtonsoft.Json.Linq.JObject)cardResult[]; if (cardObj["errmsg"] != null && cardObj["errmsg"].ToString() != "")
{
if (cardObj["errmsg"].ToString() == "ok")
{
flag = ;
}
else
{
flag = -;
}
}
}
}
}
}
else//禁止激活
{
flag = -;
}
}
else
{
flag = -;
}
}
catch (Exception ex)
{
LogError(ex);
flag = -;
}
Context.Response.Write(flag);
}
#endregion

C# 微信开发-----微信会员卡(三)激活会员卡的更多相关文章

  1. C# 微信开发-----微信会员卡(一)

    这是微信的官方文档:https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1451025283,能看懂的朋友就请不要往下看了,我是看不懂 ...

  2. C# 微信开发-----微信会员卡(二)

    主要说说如何使用微信的激活会员卡 如图: 点击激活会员卡时,要跳转到如下的图片: 要实现这个功能,首先我们在创建会员卡后就操作如下代码 #region 添加激活时的自定义字段 string custo ...

  3. C#微信开发-微信JS-SDK(1)之通过config接口注入权限验证配置

    官方文档是微信JS-SDK的使用步骤http://mp.weixin.qq.com/wiki/7/aaa137b55fb2e0456bf8dd9148dd613f.html#JSSDK.E4.BD.B ...

  4. html 微信开发——微信授权

    微信JS-SDK说明文档 链接地址:http://mp.weixin.qq.com/wiki/7/aaa137b55fb2e0456bf8dd9148dd613f.html 微信web开发:http: ...

  5. Force.com微信开发系列(三)申请测试账号及回复图文消息

    Force.com除了简单的文本消息回复外,还能回复图文并茂的消息.能回复音乐或者视频.能对用户发来的语音进行识别.能够搜集用户的地理位置信息并提供相应的内容或服务等,本文将对这些技能一一展开说明,在 ...

  6. 微信开发——微信公众平台实现消息接收以及消息的处理(Java版)

    本文主要讲述了如何在微信公众平台实现消息接收以及消息的处理,使用java语言开发,现在把实现思路和代码整理出来分先给兄弟们,希望给他们带来帮助. 温馨提示: 这篇文章是依赖前几篇的文章的. 第一篇:微 ...

  7. [微信开发] 微信网页授权Java实现

    功能:主要用于在用户通过手机端微信访问第三方H5页面时获取用户的身份信息(openId,昵称,头像,所在地等..)可用来实现微信登录.微信账号绑定.用户身份鉴权等功能.     开发前的准备: 1.需 ...

  8. 微信开发-微信JSSDK错误:invalid url domain

    错误类型:invalid url domain 调试返回参数: { "errMsg": "config:invalid url domain" } 截图: 环境 ...

  9. [微信开发] 微信JSAPI - 获取用户地理位置信息

    参考博客 http://blog.csdn.net/u013142781/article/details/50503299 主要JS 方法 wx.getLocation 获取地理位置信息传递参数 成功 ...

随机推荐

  1. idea2018.3.5永久破解教程

    视频教程地址: http://v.youku.com/v_show/id_XNDEwNDU1NjQ4MA==.html 配套笔记: ①修改配置文件 -Xms128m -Xmx750m -XX:Rese ...

  2. Python可变参数*和**

    可变参数 在Python函数中,还可以定义可变参数.顾名思义,可变参数就是传入的参数个数是可变的,可以是1个.2个到任意个,还可以是0个. 我们以数学题为例子,给定一组数字a,b,c……,请计算a2 ...

  3. Lodop的TABLE中format格式化的使用

    LODOP中的ADD_PRINT_TABLE支持很多函数和计算方法,可以用tdata对table表格里额数据进行计算,用format对结果进行格式化.这个format只能和tdata搭配使用,不能单独 ...

  4. Codeforces437 B. The Child and Set

    题目类型:位运算 传送门:>Here< 题意:给出\(sum和limit\),求一个集合\(S\),其中的元素互不相同且不超过\(limit\),他们的\(lowbit\)之和等于\(su ...

  5. Magento 2 Theme Ultimate Guide - 如何创建Magento 2主题终极指南

    Magento 2 Theme Ultimate Guide - 如何创建Magento 2主题基础指南 在Magento 2中管理和设置主题的方式有很多改进.Magento 1.9中引入的theme ...

  6. class09

    class09 四川菜很辣. Sichuan cuisine is very spicy. 那个汤是凉的. That soup is cold. 这茶很烫. This tea is very hot. ...

  7. luogu4705玩游戏

    题解 我们要对于每个t,求一个(1/mn)sigma(ax+by)^t. 把系数不用管,把其他部分二项式展开一下: simga(ax^r*by^(t-r)*C(t,r)). 把组合数拆开,就变成了一个 ...

  8. Windows 10 2016 LTS版本下载与激活

    Windows 10 2016 LTS版是针对企业用户推出的长期支持版本,有如下2个优点:1.不会被强制升级.2.去掉小娜,应用商店等不常用的功能,系统相对简洁. 安装文件下载地址如下(x86/x64 ...

  9. 洛谷P1108 低价购买题解

    看到"你必须用低于你上次购买它的价格购买它",有没有想到什么?没错,又是LIS,倒过来的LIS,所以我们只要把读入的序列倒过来就可以求LIS了,第一问解决. 首先要厘清的是,对于这 ...

  10. 计算机基础理论知识梳理篇(一):数据类型长度、内存页、IPC

    字长与数据类型长度 字长指CPU在同一时间能够处理二进制数据的位数,是由其外接数据总线(地址总线决定了CPU的寻址空间,如16位微型机的地址总线为20位,其可寻址空间为220 = 1MB)的条数决定的 ...