文档介绍:微信公众平台向特定用户推送消息
最近研究微信公众平台,这里整理了一下向特定用户推送消息的思路
一、首先需要将微信的openid与系统用户绑定。
在用户关注公众平台的时候,回复一个链接,要求用户绑定,可以设计如下消息进行回复,(openid最好进行加密处理,后者还需要用这个字段绑定fakeid)。
欢迎关注有问必答平台,<a href='?openid=***@openid'>点击此处进行用户绑定</a>!
,这个绑定过程非常简单,这里不详叙述。
二、将openid与fakeid进行绑定
微信公众平台是一回一答的模式;但是在微信公众平台后台,可以向特定用户进行消息发送。我们利用这个机制使用代码去模拟这个过程来实现消息推送。
首先需要模拟登录:
using System;
using ;
using ;
using ;
using ;
using ;
using ;
using ;
using ;
using ;
/// <summary>
///WeiXinLogin 的摘要说明
/// </summary>
public class WeiXinLogin
{
/// <summary>
/// MD5 32位加密
/// </summary>
/// <param name="str"></param>
/// <returns></returns>
static string GetMd5Str32(string str)
{
MD5CryptoServiceProvider md5Hasher = new MD5CryptoServiceProvider();
// Convert the input string to a byte array and compute the hash.
char[] temp = ();
byte[] buf = new byte[];
for (int i = 0; i < ; i++)
{
buf[i] = (byte)temp[i];
}
byte[] data = (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 < ; i++)
{
(data[i].ToString("x2"));
}
// Return the hexadecimal string.
return ();
}
public static bool ExecLogin(string name,string pass)
{
bool result = fals