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

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

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. 判断语句之if..else if...else

    判断语句之if..else if...else if语句第三种格式:if..else if...else 格式: 执行流程 首先判断关系表达式1看其结果是true还是false 如果是true就执行语 ...

  2. docker(四) 使用Dockerfile构建镜像

    下面以一个例子来演示构建镜像的过程. #在/tmp目录下演示 cd tmp mkdir build-redis-image 1.创建Dockerfile文件 vim Dockerfile 并写入如下内 ...

  3. SQL中ON和WHERE的区别

    SQL中ON和WHERE的区别 - 邃蓝星空 - 博客园 https://www.cnblogs.com/guanshan/articles/guan062.html

  4. Ubuntu 系统安装详解 19.04最新版本

    Ubuntu 19.04版本系统安装详解 1 .镜像的下载 推荐 阿里云镜像下载 2.安装 1.1.新建虚拟机 注意硬件的兼容性问题 当前只有5.x可以用,其他兼容各位可以尝试下,我也都试过,但只有5 ...

  5. Python的数据库操作

    使用原生SQL语句进行对数据库操作,可完成数据库表的建立和删除,及数据表内容的增删改查操作等.其可操作性很强,如可以直接使用“show databases”.“show tables”等语句进行表格之 ...

  6. mysql-笔记-数据类型

    https://dev.mysql.com/doc/refman/5.7/en/numeric-type-overview.html serial: SERIAL is an alias for BI ...

  7. 初步了解jQuery

    jQuery 库可以通过一行简单的标记被添加到网页中. jQuery是一个JavaScript函数库. jQuery是一个轻量级的"写的少,做的多"的JavaScript库. jQ ...

  8. 【UOJ295】【ZJOI2017】线段树 倍增

    题目大意 http://uoj.ac/problem/295 题解 考虑像 zkw 线段树一样,从 \([l-1,l-1],[r+1,r+1]\) 这两个区间开始往上跳,直到两个指针碰到一起为止. 先 ...

  9. 初学cdq分治学习笔记(可能有第二次的学习笔记)

    前言骚话 本人蒟蒻,一开始看到模板题就非常的懵逼,链接,学到后面就越来越清楚了. 吐槽,cdq,超短裙分治....(尴尬) 正片开始 思想 和普通的分治,还是分而治之,但是有一点不一样的是一般的分治在 ...

  10. Docker:跨主机容器间通信之overlay [十五]

    一.配置overlay类型网络准备工作 1.在luoahong3主机上 docker run -d -p 8500:8500 -h consul --name consul progrium/cons ...