Java给特定用户发通知_微信公众平台向特定用户推送消息

最近研究微信公众平台,这里整理了一下向特定用户推送消息的思路

一、首先需要将微信的openid与系统用户绑定。

在用户关注公众平台的时候,回复一个链接,要求用户绑定,可以设计如下消息进行回复,(openid最好进行加密处理,后者还需要用这个字段绑定fakeid)。

欢迎关注有问必答平台,点击此处进行用户绑定!

在bind.html页面将openid与系统的usercode进行绑定,这个绑定过程非常简单,这里不详叙述。

二、将openid与fakeid进行绑定

微信公众平台是一回一答的模式;但是在微信公众平台后台,可以向特定用户进行消息发送。我们利用这个机制使用代码去模拟这个过程来实现消息推送。

首先需要模拟登录:

using System;

using System.Collections.Generic;

using System.Linq;

using System.Web;

using System.Security.Cryptography;

using System.Text;

using System.Net;

using System.IO;

using System.Security.Authentication;

using System.Security.Cryptography.X509Certificates;

///

///WeiXinLogin 的摘要说明

///

public class WeiXinLogin

{

///

/// MD5 32位加密

///

///

///

static string GetMd5Str32(string str)

{

MD5CryptoServiceProvider md5Hasher = new MD5CryptoServiceProvider();

// Convert the input string to a byte array and compute the hash.

char[] temp = str.ToCharArray();

byte[] buf = new byte[temp.Length];

for (int i = 0; i < temp.Length; i++)

{

buf[i] = (byte)temp[i];

}

byte[] data = md5Hasher.ComputeHash(buf);

// Create a new Stringbuilder to collect the bytes

// and create a string.

StringBuilder sBuilder = new StringBuilder();

// Loop through each byte of the hashed data

// and format each one as a hexadecimal string.

for (int i = 0; i < data.Length; i++)

{

sBuilder.Append(data[i].ToString("x2"));

}

// Return the hexadecimal string.

return sBuilder.ToString();

}

public static bool ExecLogin(string name,string pass)

{

bool result = false;

string password = GetMd5Str32(pass).ToUpper();

string padata = "username=" + name + "&pwd=" + password + "&a

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值