微信公众平台,简称weChat。曾命名为“官号平台”和“媒体平台”,最终定位为“公众平台”,无疑让我们看到一个微信对后续更大的期望。和新浪微博早期从明星战略着手不同,微信此时已经有了亿级的用户,挖掘自己用户的价值,为这个新的平台增加更优质的内容,创造更好的粘性,形成一个不一样的生态循环,是平台发展初期更重要的方向。利用公众账号平台进行自媒体活动,简单来说就是进行一对多的媒体性行为活动,如商家通过申请公众微信服务号通过二次开发展示商家微官网、微会员、微推送、微支付、微活动,微报名、微分享、微名片等,已经形成了一种主流的线上线下微信互动营销方式。
@Controller@RequestMapping(value = "/hello")public class HelloController { private static final String url = "http://f5b3cbc2.ngrok.io" + "/weixin/"; /** * 微信接入验证 * * @desc 1. 将token、timestamp、nonce三个参数进行字典序排序 * @desc 2. 将三个参数字符串拼接成一个字符串进行sha1加密 * @desc 3. 开发者获得加密后的字符串可与signature对比,标识该请求来源于微信 * */ @RequestMapping(value = "/accept.do", method = RequestMethod.GET) @ResponseBody public String accept(String signature, String timestamp, String nonce, String echostr) { if (WeChatUtils.checkSignature(signature, timestamp, nonce)) { return echostr; } return null; }}
public class WeChatUtils { private static final String token = "hello"; public static Boolean checkSignature(String signature, String timestamp, String nonce) { //sort String[] arr = new String[] { token, timestamp, nonce }; Arrays.sort(arr); StringBuffer sf = new StringBuffer(); for (int i = 0; i < arr.length; i++) { sf.append(arr[i]); } //sha1加密 MessageDigest md; try { md = MessageDigest.getInstance("SHA"); // 执行摘要方法 byte[] digest = md.digest(sf.toString().getBytes()); String encriptStr = new HexBinaryAdapter().marshal(digest); if (encriptStr.equalsIgnoreCase(signature)) { return true; } } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } return false; }}
$(function () {
$(‘pre.prettyprint code‘).each(function () {
var lines = $(this).text().split(‘\n‘).length;
var $numbering = $(‘