Ejemplo n.º 1
0
/**
 * 支持各个分离系统的会员信息对接
 * @author winsen
 * @date 2014-11-20
 */
include '../library/init.inc.php';
$loader->includeClass('Rsa');
//接收数据统一使用json格式的RSA私钥加密的密文的base64编码字符串
//返回也是相同的格式
$data = isset($_POST['data']) ? $_POST['data'] : '';
$data = str_replace(' ', '+', $data);
$response = array();
$rsa = new Rsa();
if ($data) {
    $data = $rsa->public_key_decrypt($data, 'base64', 'key/outer_public_key.pem');
    if ($data) {
        $data = json_decode($data);
    }
    if ($data->opera == 'get') {
        $code = $data->code;
        //OAuth用于获取accessToken的code
        $publicAccount = $db->escape($data->account);
        //需要对接程序提供公众号信息
        $getInfo = 'select `appID`,`appsecret` from `' . $db_prefix . 'publicAccount` where `account`=\'' . $publicAccount . '\'';
        $info = $db->fetchRow($getInfo);
        $url = 'https://api.weixin.qq.com/sns/oauth2/access_token?appid=%s&secret=%s&code=%s&grant_type=authorization_code';
        $url = sprintf($url, $info['appID'], $info['appsecret'], $code);
        $wechatInfo = get($url);
        $wechatInfo = json_decode($wechatInfo);
        if (isset($wechatInfo->errcode)) {