qq会员礼包接入的坑

来源:互联网 发布:网络电视看vap可要收费 编辑:程序博客网 时间:2024/06/11 20:50

1、提示用户未登录,请重试!(在QQ会员后台配置的appId和appKey是ysdk申请到的qq appId和appKey)
2、发货地址不能是https,礼包id只能为纯数字,发货key是单独的一个key,可以不同于appkey,但是需要腾讯配置,否则支付成功提示网络错误

附上 QQ 会员特权页数字签名代码:

import java.security.MessageDigest;import java.util.ArrayList;import java.util.Collection;import java.util.Collections;import java.util.HashMap;public class Signature {    /**     * appid:手q的appId     * openid:qq / 微信 登录后获取到的openId     * openkey:qq的access_token  / 微信可以是任意一个字符串值,但是不能空     * partition:区服      * roleid:礼包id     * @param args     * @throws Exception     */    public static void main(String[] args) throws Exception{        //qq会员签名        String str="appid=2561230286&openid=sfsfadfghfd&openkey=tewsgddfvfd&partition=11&roleid=4543";        sign(str);    }    private static void sign(String str){    String[] list=str.split("&");    HashMap<String, String> hash=new HashMap<String, String>();    ArrayList<String> key=new ArrayList<String>();        for(int i=0;i<list.length;i++){            if(list[i].startsWith("_")){                continue;            }else{                String[] keyvalue=list[i].split("=");                hash.put(keyvalue[0], keyvalue[1]);                key.add(keyvalue[0]);            }        }        Collections.sort(key);        StringBuffer sb=new StringBuffer();        for(int i=0;i<key.size();i++){            sb.append(key.get(i));            sb.append("="+hash.get(key.get(i))+"&");        }        //修改自己的appkey        sb.append("appkey=XXdu09eNcOlf");        System.out.println("加密原文:"+sb);        try {            MD5Encode(sb.toString());        } catch (Exception e) {            e.printStackTrace();        }    }    public static void MD5Encode(String inStr) throws Exception {        MessageDigest md5 = null;        try {            md5 = MessageDigest.getInstance("MD5");        } catch (Exception e) {            System.out.println(e.toString());            e.printStackTrace();        }        byte[] byteArray = inStr.getBytes("UTF-8");        byte[] md5Bytes = md5.digest(byteArray);        StringBuffer hexValue = new StringBuffer();        for (int i = 0; i < md5Bytes.length; i++) {            int val = ((int) md5Bytes[i]) & 0xff;            if (val < 16) {                hexValue.append("0");            }            hexValue.append(Integer.toHexString(val));        }       System.out.println("加密结果:"+hexValue.toString());    }}