您的位置:首页 > 移动开发 > 微信开发

微信服务号服务器配置和企业号回调接口配置的区别

2016-12-18 10:30 429 查看
1、

服务号,订阅号

配置微信服务号在左侧菜单基本配置,名称叫服务器配置,可以采用三种加解密模式





企业号

回调接口位于应用中心--》点击某个消息型应用(没有可以创建)--》模式选择(选择回调模式)--》回调URL及密钥



2、微信企业号是在微信服务号后出来的,在加密方式上有些不一样

微信提供的加密包,

http://qydev.weixin.qq.com/wiki/index.php?title=%E5%8A%A0%E8%A7%A3%E5%AF%86%E5%BA%93%E4%B8%8B%E8%BD%BD%E4%B8%8E%E8%BF%94%E5%9B%9E%E7%A0%81

csdn下载地址

3、注意事项

1.,其中WXBizMsgCrypt.java文件提供的WXBizMsgCrypt类封装了用户接入微信的三个接口,其它的类文件用户用于实现加解密,用户无须关心。

2.WXBizMsgCrypt封装了VerifyURL, DecryptMsg, EncryptMsg三个接口,分别用于开发者验证回调url、接收消息的解密以及开发者回复消息的加密过程。

3.请开发者使用jdk1.6或以上的版本。针对org.apache.commons.codec.binary.Base64,需要导入jar包commons-codec-1.9(或comm ons-codec-1.8等其他版本),我们有提供,官方下载地址:

http://commons.apache.org/proper/commons-codec/download_codec.cgi

jdk 加解密包的csdn下载地址http://download.csdn.net/detail/u014520797/9701143

4、在微信服务号安全模式服务器配置时与企业号不同是SHA1类的不同

①服务号的SHA1类,getSHA1(token, timeStamp, nonce)方法只需要token, timestamp, nonce三个参数进行SHA1算法生成安全签名,getSHA2(token, timeStamp, nonce, encrypt)方法用于消息加密,所以服务号的SHA1类需要两个方法。企业号只需要getSHA2(token,
timeStamp, nonce, encrypt)方法。

/**
* 对公众平台发送给公众账号的消息加解密示例代码.
*
* @copyright Copyright (c) 1998-2014 Tencent Inc.
*/

// ------------------------------------------------------------------------

package com.kp.aes;

import java.security.MessageDigest;
import java.util.Arrays;

/**
* SHA1 class
*
* 计算公众平台的消息签名接口.
*/
class SHA1 {

/**
* 用SHA1算法生成安全签名
* @param token 票据
* @param timestamp 时间戳
* @param nonce 随机字符串
* @param encrypt 密文
* @return 安全签名
* @throws AesException
*/
public static String getSHA1(String token, String timestamp, String nonce) throws AesException
{
try {
//与企业号不同2
String[] array = new String[] { token, timestamp, nonce };
StringBuffer sb = new StringBuffer();
// 字符串排序
Arrays.sort(array);
for (int i = 0; i < array.length; i++) {
sb.append(array[i]);
}
String str = sb.toString();
// SHA1签名生成
MessageDigest md = MessageDigest.getInstance("SHA-1");
md.update(str.getBytes());
byte[] digest = md.digest();

StringBuffer hexstr = new StringBuffer();
String shaHex = "";
for (int i = 0; i < digest.length; i++) {
shaHex = Integer.toHexString(digest[i] & 0xFF);
if (shaHex.length() < 2) {
hexstr.append(0);
}
hexstr.append(shaHex);
}
return hexstr.toString();
} catch (Exception e) {
e.printStackTrace();
throw new AesException(AesException.ComputeSignatureError);
}
}

/**
* @param token
* @param timestamp
* @param nonce
* @param encrypt
* @throws AesException String
* @Des:  加密消息用SHA2  这点与企业号不同
*/
public static String getSHA2(String token, String timestamp, String nonce, String encrypt) throws AesException
{
try {
//与企业号不同2
String[] array = new String[] { token, timestamp, nonce,encrypt};
StringBuffer sb = new StringBuffer();
// 字符串排序
Arrays.sort(array);
for (int i = 0; i < array.length; i++) {
sb.append(array[i]);
}
String str = sb.toString();
// SHA1签名生成
MessageDigest md = MessageDigest.getInstance("SHA-1");
md.update(str.getBytes());
byte[] digest = md.digest();

StringBuffer hexstr = new StringBuffer();
String shaHex = "";
for (int i = 0; i < digest.length; i++) {
shaHex = Integer.toHexString(digest[i] & 0xFF);
if (shaHex.length() < 2) {
hexstr.append(0);
}
hexstr.append(shaHex);
}
return hexstr.toString();
} catch (Exception e) {
e.printStackTrace();
throw new AesException(AesException.ComputeSignatureError);
}
}
}


企业号的SHA1类,需要token, timestamp, nonce,encrypt四个参数进行SHA1算法生成安全签名

public static String getSHA2(String token, String timestamp, String nonce, String encrypt) throws AesException
{
try {
//与企业号不同2
String[] array = new String[] { token, timestamp, nonce,encrypt};
StringBuffer sb = new StringBuffer();
// 字符串排序
Arrays.sort(array);
for (int i = 0; i < array.length; i++) {
sb.append(array[i]);
}
String str = sb.toString();
// SHA1签名生成
MessageDigest md = MessageDigest.getInstance("SHA-1");
md.update(str.getBytes());
byte[] digest = md.digest();

StringBuffer hexstr = new StringBuffer();
String shaHex = "";
for (int i = 0; i < digest.length; i++) {
shaHex = Integer.toHexString(digest[i] & 0xFF);
if (shaHex.length() < 2) {
hexstr.append(0);
}
hexstr.append(shaHex);
}
return hexstr.toString();
} catch (Exception e) {
e.printStackTrace();
throw new AesException(AesException.ComputeSignatureError);
}
}


5、总结:加密这块感觉微信文档这边有些混乱,微信支付更乱

①在获取签名时不同

// 微信企业号为msg_signature
String msg_signature = request.getParameter("msg_signature");

                //微信服务号
String signature = request.getParameter("signature");

②SHA1类不同,

企业号需要token, timestamp, nonce,encrypt四个参数进行SHA1算法生成安全签名,一个getSHA2(token, timeStamp, nonce, encrypt)

服务号需要token, timestamp, nonce 3个参数进行SHA1算法生成安全签名,一个getSHA1(token,
timeStamp, nonce)

,一个getSHA2(token, timeStamp, nonce, encrypt),共两个方法

③WXBizMsgCrypt不同

因为SHA1类的不同,导致调用SHA1类的WXBizMsgCrypt的不同

WXBizMsgCrypt主要有三个方法,DecryptMsg方法,EncryptMsg方法,VerifyURL方法,前两者方法用于安全模式中的消息加解密,第三个方法用于url配置(服务器配置)

在服务号中:

DecryptMsg方法和VerifyURL方法使用SHA1类的getSHA1(token,
timeStamp, nonce)方法

EncryptMsg方法使用SHA1类的getSHA2(token,
timeStamp, nonce, encrypt)方法

在企业号中:

DecryptMsg方法,EncryptMsg方法,VerifyURL方法都使用SHA1类的getSHA2(token,
timeStamp, nonce, encrypt)方法

6、微信企业号回调接口配置http://blog.csdn.net/u014520797/article/details/49720601

微信服务号基本配置http://blog.csdn.net/u014520797/article/details/53725287

服务号demo下载:http://download.csdn.net/detail/u014520797/9714496

企业号demo下载:http://download.csdn.net/detail/u014520797/9726045

企业号回调接口demo http://download.csdn.net/detail/u014520797/9252951
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
相关文章推荐