package com.qs.mp.web.controller.api.common;

import cn.hutool.json.JSONUtil;
import cn.jsms.api.ValidSMSResult;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.TypeReference;
import com.alibaba.fastjson.parser.Feature;
import com.alipay.api.AlipayApiException;
import com.alipay.api.AlipayClient;
import com.alipay.api.DefaultAlipayClient;
import com.alipay.api.internal.util.AlipayEncrypt;
import com.alipay.api.internal.util.AlipaySignature;
import com.alipay.api.request.AlipaySystemOauthTokenRequest;
import com.alipay.api.request.AlipayUserInfoShareRequest;
import com.alipay.api.response.AlipaySystemOauthTokenResponse;
import com.alipay.api.response.AlipayUserInfoShareResponse;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.qs.mp.channel.domain.Channel;
import com.qs.mp.channel.service.IChannelService;
import com.qs.mp.common.core.domain.AjaxResult;
import com.qs.mp.common.domain.vo.AliPhoneDecryptVO;
import com.qs.mp.common.enums.UserIdentityEnum;
import com.qs.mp.common.enums.WxActTypeEnum;
import com.qs.mp.common.jsms.JSMSUtils;
import com.qs.mp.common.qcloud.QcloudFileUtils;
import com.qs.mp.common.utils.LogUtil;
import com.qs.mp.common.utils.StringUtils;
import com.qs.mp.common.utils.UUIDUtils;
import com.qs.mp.common.utils.http.HttpUtils;
import com.qs.mp.core.domain.LoginUser;
import com.qs.mp.framework.domain.WxAccount;
import com.qs.mp.framework.security.handle.HostHolder;
import com.qs.mp.framework.service.IAppTokenService;
import com.qs.mp.framework.service.IWxAccountService;
import com.qs.mp.framework.web.service.SysLoginService;
import com.qs.mp.system.domain.SysUser;
import com.qs.mp.system.domain.vo.WxLoginParams;
import com.qs.mp.system.service.ISysUserService;
import com.qs.mp.utils.SecurityUtils;
import com.qs.mp.web.controller.common.BaseApiController;
import io.swagger.annotations.Api;

import java.io.File;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.Date;
import java.util.List;
import java.util.Map;
import javax.crypto.Cipher;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;

import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.io.FileUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.*;
import sun.misc.BASE64Decoder;

/**
 * @auther duota
 * @create 2021 2021/9/6 6:16 下午
 * @describe
 */

@Api("用户钱包API")
@RestController
@RequestMapping("/api/v1/mp")
@Component
public class UserController extends BaseApiController {

    @Autowired
    private ISysUserService sysUserService;

    @Autowired
    protected HostHolder hostHolder;

    @Autowired
    private IWxAccountService wxAccountService;

    @Autowired
    private IChannelService channelService;

    @Value("${wx-channel.appId}")
    private String channelAppId;
    @Value("${wx-channel.appSecret}")
    private String channelAppSecret;

    @Value("${wx-user.appId}")
    private String userAppId;
    @Value("${wx-user.appSecret}")
    private String userAppSecret;

    @Value("${ali-miniApp.appId}")
    private String aliAppId;
    @Value("${ali-miniApp.public-key}")
    private String aliPublicKey;
    @Value("${ali-miniApp.private-key}")
    private String aliPrivateKey;

    @Value("${ali-miniApp.serverUrl}")
    private String aliServerUrl;

    @Value("${ali-miniApp.decrypt-key}")
    private String decryptKey;

    /**
     * 文件上传路径
     */
    @Value("${mp.profile}")
    public String filePath;

    /**
     * 公开
     */
    @Value("${cloud.public-bucket-name}")
    private String publicBucketName;

    @Autowired
    private IAppTokenService appTokenService;

    @Autowired
    private SysLoginService sysLoginService;

    private static final String CBC_CIPHER_ALGORITHM = "AES/CBC/PKCS5Padding";
    private static final String KEY_ALGORITHM = "AES";
    private static final String UTF8 = "UTF-8";


    @ApiOperation("支付宝获取用户手机号")
    @PostMapping("/user/aliAuth/mobile")
    public AjaxResult aliAuthMobile(@RequestBody WxLoginParams wxLoginParams) {

        String response = wxLoginParams.getEncryptedData();

        //1. 获取验签和解密所需要的参数
        Map<String, String> openapiResult = JSON.parseObject(response,
                new TypeReference<Map<String, String>>() {
                }, Feature.OrderedField);
        String signType = "RSA2";
        String charset = "UTF-8";
        String encryptType = "AES";
        String sign = openapiResult.get("sign");
        String content = openapiResult.get("response");

        // 是否加密
        boolean isDataEncrypted = !content.startsWith("{");
        boolean signCheckPass = false;

        //2. 验签
        String signContent = content;
        String signVeriKey = aliPublicKey;
        // 如果是加密的报文则需要在密文的前后添加双引号
        if (isDataEncrypted) {
            signContent = "\"" + signContent + "\"";
        }
        try {
            signCheckPass = AlipaySignature.rsaCheck(signContent, sign, signVeriKey, charset, signType);
        } catch (AlipayApiException e) {
            // 验签异常, 日志
            LogUtil.error(logger, "验签异常:{0}", e.getMessage());
        }
        if (!signCheckPass) {
            // 验签不通过（异常或者报文被篡改），终止流程（不需要做解密）
            LogUtil.warn(logger, "验签失败");
            return AjaxResult.error("验签失败");
        }

        //3. 解密
        String plainData = null;
        if (isDataEncrypted) {
            try {
                plainData = AlipayEncrypt.decryptContent(content, encryptType, decryptKey, charset);
            } catch (AlipayApiException e) {
                //解密异常, 记录日志
                LogUtil.warn(logger, "解密异常");
                return AjaxResult.error("解密异常");
            }
        } else {
            plainData = content;
        }

        // 转对象 异常情况处理

        AliPhoneDecryptVO aliPhoneDecryptVO = JSONUtil.toBean(plainData, AliPhoneDecryptVO.class);
        if (!aliPhoneDecryptVO.isSuccess()) {
            LogUtil.error(logger, "解析手机号失败,errorMsg:{0}", plainData);
            return AjaxResult.error("解析手机号失败," + aliPhoneDecryptVO.getSubMsg());
        }
        String mobile = aliPhoneDecryptVO.getMobile();

        AjaxResult ajax = AjaxResult.success();
        SysUser sysUser = sysUserService.selectUserByUserName(mobile);
        if (null == sysUser) {
            if (wxLoginParams.getIdentity() != UserIdentityEnum.USER.ordinal()) {
                return error("用户不存在，请联系客服");
            }
            // C端直接注册新用户
            sysUser = new SysUser();
            sysUser.setUserName(mobile);
            sysUser.setNickName(mobile);
            sysUser.setPhonenumber(mobile);
            sysUserService.registerUser(sysUser);
        }
        Map<String, String> result = sysLoginService.wxAuthLogin(mobile, wxLoginParams.getIdentity());
        for (String key : result.keySet()) {
            ajax.put(key, result.get(key));
        }
        return ajax;
    }


    @ApiOperation("支付宝授权登录")
    @PostMapping("/user/aliAuth")
    public AjaxResult aliAuth(@RequestBody WxLoginParams wxLoginParams) {
        String code = wxLoginParams.getCode();
        if (StringUtils.isBlank(code)) {
            return AjaxResult.error("code码不存在");
        }

        AlipayClient alipayClient = new DefaultAlipayClient(aliServerUrl, aliAppId, aliPrivateKey, "json", "GBK", aliPublicKey, "RSA2");
        AlipaySystemOauthTokenRequest request = new AlipaySystemOauthTokenRequest();
        request.setGrantType("authorization_code");
        request.setCode(code);
        AlipaySystemOauthTokenResponse response = null;
        try {
            response = alipayClient.execute(request);
        } catch (AlipayApiException e) {
            LogUtil.error(logger, "获取支付宝授权令牌失败,errorMsg:{0}", e.getMessage());
            return AjaxResult.error("获取授权令牌失败");
        }
        if (!response.isSuccess()) {
            return AjaxResult.error("获取授权令牌调用失败");
        }
        LogUtil.info(logger, "授权令牌信息:{0}", JSONUtil.toJsonStr(response));
        // 支付宝小程序userId
        String aliUserId = response.getUserId();
        // 访问令牌
        String accessToken = response.getAccessToken();

        // 根据访问令牌获取用户基本信息
        AlipayUserInfoShareRequest userInfoRequest = new AlipayUserInfoShareRequest();
        AlipayUserInfoShareResponse userInfoResponse = null;
        try {
            userInfoResponse = alipayClient.execute(userInfoRequest, accessToken);
        } catch (AlipayApiException e) {
            LogUtil.error(logger, "获取用户基本信息失败,errorMsg:{0}", e.getMessage());
            return AjaxResult.error("获取用户基本信息失败");
        }
        if (!userInfoResponse.isSuccess()) {
            return AjaxResult.error("获取用户基本信息失败");
        }
        LogUtil.info(logger, "用户基本信息:{0}", JSONUtil.toJsonStr(userInfoResponse));


        // 更新数据库用户授权信息
        LoginUser loginUser = SecurityUtils.getLoginUser();
        SysUser user = new SysUser();
        user.setUserId(loginUser.getUserId());
        user.setLoginDate(new Date());
        user.setAliuserId(aliUserId);
        user.setNickName(userInfoResponse.getNickName());
        // 如果用户头像字段为空,则默认获取用户支付宝头像
        String avatarUrl = userInfoResponse.getAvatar();

        if (StringUtils.isBlank(loginUser.getUser().getAvatar()) && !StringUtils.isBlank(avatarUrl)) {
            try {
                //下载并且重新上传头像
                JSONObject result = saveHeadImage(avatarUrl, String.valueOf(user.getUserId()));
                if (result != null) {
                    user.setAvatar(result.getString("fileName"));
                }
            } catch (Exception e) {
                LogUtil.error(logger, "头像上传异常", e.getMessage());
            }
        }
        logger.info("更新用户数据:" + JSONUtil.toJsonStr(user));
        int rows = sysUserService.updateUserProfile(user);
        if (rows != 1) {
            LogUtil.error(logger, "用户支付宝授权异常");
            return error("用户支付宝授权异常");
        }
        JSONObject rst = new JSONObject();
        rst.put("aliUserId", aliUserId);
        return success(rst);
    }

    @ApiOperation("微信授权登录")
    @RequestMapping(value = "/user/wxauth", method = RequestMethod.POST)
    @ResponseBody
    public AjaxResult wxauth(@RequestBody WxLoginParams wxLoginParams) {
        String appId = channelAppId;
        String appSecret = channelAppSecret;
        if (wxLoginParams.getIdentity() == UserIdentityEnum.USER.ordinal()) {
            appId = userAppId;
            appSecret = userAppSecret;
        }
        //调用微信后台接口获取openId
        String res = wxLoginCheck(wxLoginParams.getCode(), appId, appSecret);
        JSONObject jsonObject = JSONObject.parseObject(res);
        String openId = jsonObject.getString("openid");
        String sessionKey = jsonObject.getString("session_key");
        String unionId = jsonObject.getString("unionid");

        if (StringUtils.isBlank(openId) || StringUtils.isBlank(sessionKey)) {
            LogUtil.error(logger, "微信登录失败:" + jsonObject.toJSONString());
            return error("登录失败");
        }
        //更新数据库用户授权信息
        LoginUser loginUser = SecurityUtils.getLoginUser();
        SysUser user = new SysUser();
        user.setUserId(loginUser.getUserId());
        if (wxLoginParams.getIdentity() == UserIdentityEnum.USER.ordinal()) {
            user.setOpenId(openId);
        } else {
            user.setChannelOpenId(openId);
        }

        user.setSessionKey(sessionKey);
        user.setUnionId(unionId);
        user.setLoginDate(new Date());
        user.setNickName(wxLoginParams.getNickName());
        //如果用户头像字段为空，则默认获取用户微信头像
        String avatarUrl = wxLoginParams.getAvatarUrl();

        //用户先关联过公众号，那么授权后进行自动绑定
        LambdaQueryWrapper<WxAccount> wrapper = new LambdaQueryWrapper();
        wrapper.eq(WxAccount::getUnionid, unionId);
        wrapper.eq(WxAccount::getActType, WxActTypeEnum.GZH.getValue());
        List<WxAccount> accountList = wxAccountService.list(wrapper);
        if (accountList.size() == 1) {
            user.setGzhOpenId(accountList.get(0).getOpenid());
        }
        if (StringUtils.isBlank(loginUser.getUser().getAvatar()) && !StringUtils.isBlank(avatarUrl)) {
            try {
                //下载并且重新上传头像
                JSONObject result = saveHeadImage(avatarUrl, String.valueOf(user.getUserId()));
                if (result != null) {
                    user.setAvatar(result.getString("fileName"));
                }
            } catch (Exception e) {
                LogUtil.error(logger, "头像上传异常", e.getMessage());
            }
        }
        logger.info("update user data:" + JSONObject.toJSONString(user));
        int rows = sysUserService.updateUserProfile(user);
        if (rows != 1) {
            LogUtil.error(logger, "用户微信授权异常");
            return error("用户微信授权异常");
        }
        JSONObject rst = new JSONObject();
        rst.put("openId", openId);
        return success(rst);
    }


    @ApiOperation("微信授权获取用户手机号")
    @RequestMapping(value = "/user/wxauth/mobile", method = RequestMethod.POST)
    @ResponseBody
    public AjaxResult wxauthMobile(@RequestBody WxLoginParams wxLoginParams) {
        String appId = userAppId;
        String appSecret = userAppSecret;
    /*if (UserIdentityEnum.isChannel(wxLoginParams.getIdentity())) {
      appId = channelAppId;
      appSecret = channelAppSecret;
    }*/
        JSONObject phoneInfo;
        if (StringUtils.isNotBlank(wxLoginParams.getCode())) {
            //调用微信后台接口获取openId
            String res = getWxMobile(wxLoginParams, appId);
            JSONObject jsonObject = JSONObject.parseObject(res);
            int errcode = jsonObject.getIntValue("errcode");
            if (errcode != 0) {
                LogUtil.error(logger, "手机号获取失败:" + res);
                return error("手机号获取失败");
            }
            phoneInfo = jsonObject.getJSONObject("phone_info");
        } else {
            //调用微信后台接口获取openId
            String rtn = wxLoginCheck(wxLoginParams.getLoginCode(), appId, appSecret);
            JSONObject jsonObject = JSONObject.parseObject(rtn);
            String openId = jsonObject.getString("openid");
            String sessionKey = jsonObject.getString("session_key");

            if (StringUtils.isBlank(openId) || StringUtils.isBlank(sessionKey)) {
                LogUtil.error(logger, "微信登录失败:" + jsonObject.toJSONString());
                return error("登录失败");
            }

            String res = weixinDecrypt(wxLoginParams.getEncryptedData(), sessionKey, wxLoginParams.getIv());
            if (StringUtils.isBlank(res)) {
                return error("手机号获取失败");
            }
            /**
             * {
             *     "phoneNumber": "13580006666",
             *     "purePhoneNumber": "13580006666",
             *     "countryCode": "86",
             *     "watermark":
             *     {
             *         "appid":"APPID",
             *         "timestamp": TIMESTAMP
             *     }
             * }
             */
            phoneInfo = JSON.parseObject(res);
            JSONObject watermark = phoneInfo.getJSONObject("watermark");
            if (!appId.equals(watermark.getString("appid"))) {
                LogUtil.error(logger, "手机号解密appid不符，appid:{0}", watermark.getString("appid"));
                return error("手机号获取失败");
            }
        }
        String phoneNumber = phoneInfo.getString("phoneNumber");

        if (StringUtils.isBlank(phoneNumber)) {
            LogUtil.error(logger, "微信手机号不存在:" + phoneInfo);
            return error("手机号获取失败");
        }
        AjaxResult ajax = AjaxResult.success();

        SysUser sysUser = sysUserService.selectUserByUserName(phoneNumber);
        if (null == sysUser) {
            if (wxLoginParams.getIdentity() != UserIdentityEnum.USER.ordinal()) {
                return error("用户不存在，请联系客服");
            }
            // C端直接注册新用户
            sysUser = new SysUser();
            sysUser.setUserName(phoneNumber);
            sysUser.setNickName(phoneNumber);
            sysUser.setPhonenumber(phoneNumber);
            sysUserService.registerUser(sysUser);
        }
        Map<String, String> result = sysLoginService.wxAuthLogin(phoneNumber, wxLoginParams.getIdentity());
        for (String key : result.keySet()) {
            ajax.put(key, result.get(key));
        }
        return ajax;
    }

    /**
     * 重置密码
     */
    @RequestMapping(value = "/user/resetPwd", method = RequestMethod.POST)
    public AjaxResult resetPwd(@RequestBody JSONObject user) {
        //验证短信验证码
        ValidSMSResult res = JSMSUtils.sendValidSMSCode(
                user.getString("messageId"), user.getString("code"));
        if (res == null || !res.getIsValid()) {
            return error("短信验证码错误");
        }

        int rows = sysUserService.resetUserPwd(user.getString("userName"),
                SecurityUtils.encryptPassword(user.getString("password")));
        if (rows == 1) {
            return success("密码修改成功.");
        } else {
            return error("密码修改失败");
        }
    }

    /**
     * 查询当前登录用户信息
     */
    @ApiOperation("查询当前登录用户信息")
    @RequestMapping(value = "/user/getLoginUserinfo", method = RequestMethod.POST)
    public AjaxResult getLoginUserinfo(@RequestBody JSONObject params) {
        LoginUser loginUser = SecurityUtils.getLoginUser();
        SysUser sysUser = sysUserService.selectUserById(SecurityUtils.getUserId());

        JSONObject jsonObject = new JSONObject();
        jsonObject.put("userName", sysUser.getUserName());
        jsonObject.put("avatar", sysUser.getAvatar());
        if (loginUser.getIdentity() == UserIdentityEnum.CHANNEL) {
            Channel channel = channelService.getById(loginUser.getChannelId());
            jsonObject.put("nickName", channel.getName());
        } else {
            jsonObject.put("nickName", sysUser.getNickName());
        }
        jsonObject.put("openId", sysUser.getOpenId());
        jsonObject.put("channelOpenId", sysUser.getChannelOpenId());
        jsonObject.put("aliuserId", sysUser.getAliuserId());
        JSONArray roleKeys = new JSONArray();
        JSONArray roles = new JSONArray();
        loginUser.getUser().getRoles().forEach(sysRole -> roles.add(sysRole.getRoleName()));
        jsonObject.put("roleKeys", roleKeys);
        jsonObject.put("roles", roles);
        jsonObject.put("userId", SecurityUtils.getUserId());

        return success(jsonObject);
    }


    /**
     * code 换取 session_key
     *
     * @param
     * @return
     */
    private String wxLoginCheck(String code, String appId, String appSecret) {
        String param = "appid=" + appId + "&secret=" + appSecret + "&js_code=" + code
                + "&grant_type=authorization_code";
        String res = HttpUtils.sendGet("https://api.weixin.qq.com/sns/jscode2session", param);
        return res;
    }

    /**
     * code 换取 手机号
     * {
     * "errcode":0,
     * "errmsg":"ok",
     * "phone_info": {
     * "phoneNumber":"xxxxxx",
     * "purePhoneNumber": "xxxxxx",
     * "countryCode": 86,
     * "watermark": {
     * "timestamp": 1637744274,
     * "appid": "xxxx"
     * }
     * }
     * }
     *
     * @param
     * @return
     */
    private String getWxMobile(WxLoginParams params, String appId) {
        String accessToken = appTokenService.getAccessToken(appId);
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("code", params.getCode());
        LogUtil.info(logger, JSONObject.toJSONString(params));
        String res = HttpUtils.sendPost("https://api.weixin.qq.com/wxa/business/getuserphonenumber?access_token=" + accessToken, jsonObject.toJSONString());
        return res;
    }

    /**
     * { "subscribe": 1, "openid": "o6_bmjrPTlm6_2sgVt7hMZOPfL2M", "nickname": "Band", "sex": 1,
     * "language": "zh_CN", "city": "广州", "province": "广东", "country": "中国", "headimgurl":
     * "http://wx.qlogo.cn/mmopen/g3MonUZtNHkdmzicIlibx6iaFqAc56vxLSUfpb6n5WKSYVY0ChQKkiaJSgQ1dZuTOgvLLrhJbERQQ4eMsv84eavHiaiceqxibJxCfHe/0",
     * "subscribe_time": 1382694957, "unionid": " o6_bmasdasdsad6_2sgVt7hMZOPfL" }
     *
     * @param accessToken
     * @param openId
     * @return
     */
    private String getWxUserInfo(String accessToken, String openId) {
        String url = "https://api.weixin.qq.com/cgi-bin/user/info";
        String params = "access_token=" + accessToken + "&openid=" + openId + "&lang=zh_CN";
        String res = HttpUtils.sendGet(url, params);
        logger.info("weixin user info :" + res);
        return res;
    }

    private JSONObject saveHeadImage(String serverUrl, String userId) throws Exception {
        String outFilePath = filePath + "/headImage";
        File outPath = new File(outFilePath);
        if (!outPath.exists()) {
            if (!outPath.mkdirs()) {
                throw new Exception("makdirs: '" + outFilePath + "'fail");
            }
        }
        URL url = new URL(serverUrl);
        HttpURLConnection conn = (HttpURLConnection) url.openConnection();
        conn.setConnectTimeout(3 * 1000);
        //防止屏蔽程序抓取而放回403错误
        conn.setRequestProperty("User-Agent", "Mozilla/4.0(compatible;MSIE 5.0;Windows NT;DigExt)");
        Long totalSize = Long.parseLong(conn.getHeaderField("Content-Length"));
        String name = userId + "/" + UUIDUtils.newId();
        String mimeType = "image/jpg";
        //logger.info("图片开始下载. totalSize" + totalSize);
        if (totalSize > 0) {
            File file = new File(outFilePath + "/" + userId);
            FileUtils.copyURLToFile(url, file);
            //logger.info("图片下载完成.");
            QcloudFileUtils.putFile(file, name, publicBucketName, mimeType);
            FileUtils.delete(file);
        } else {
            throw new Exception("can not find serverUrl :{}" + serverUrl);
        }
        JSONObject result = new JSONObject();
        result.put("fileName", name);
        result.put("fileType", mimeType);
        return result;
    }

    /**
     * 带有初始变量的解密（微信用）
     *
     * @param content     密文
     * @param skey        密钥
     * @param ivParameter 初始向量
     * @return
     * @throws Exception
     */
    public String weixinDecrypt(String content, String skey, String ivParameter) {
        try {
            BASE64Decoder decoder = new BASE64Decoder();
            // 根据微信文档要求需要把 密文、密钥、iv 使用BASE64进行解码
            byte[] keyByte = decoder.decodeBuffer(skey);
            byte[] contentByte = decoder.decodeBuffer(content);
            byte[] ivByte = decoder.decodeBuffer(ivParameter);
            // 生成密码
            SecretKeySpec keySpec = new SecretKeySpec(keyByte, KEY_ALGORITHM);
            // 生成IvParameterSpec
            IvParameterSpec iv = new IvParameterSpec(ivByte);
            // 初始化解密 指定模式 AES/CBC/PKCS5Padding
            Cipher cipher = Cipher.getInstance(CBC_CIPHER_ALGORITHM);
            // 指定解密模式 传入密码 iv
            cipher.init(Cipher.DECRYPT_MODE, keySpec, iv);
            // 解密
            byte[] result = cipher.doFinal(contentByte);
            return new String(result, UTF8);
        } catch (Exception e) {
            LogUtil.error(logger, e, "【解密错误】content:{0},ivParameter:{1}", new Object[]{content, ivParameter});
            return null;
        }
    }

    public static void main(String[] args) throws AlipayApiException {
//    UserController userController = new UserController();
//    System.out.println(userController.weixinDecrypt("qvNE+SHdiP2GTbmNaqahrhhLw7EZetcMhUMV9yPXHxBbWOMcZ5gFxOGliXC9uojyC0NDUXCUi1xvFVDKMYREQ7rLXXrZIkB1jEleJNuUb9kO3LCDRucvbGAbVwm2EsTNsd5VbqI3fKdu0IOxmmSAWCLZNGXZBlki4ke62lI+ASg6dPohQmmCux8jwD2Js3ZnDQN2mb0JPRT68Qj716gYvA==", "QJ/WdeFANTIfIErOCJ2jNg==", "60YJmIckq4kaXp88wAGGHA=="));

        String charset = "UTF-8";
        String encryptType = "AES";

        String publicKey1 = "fhixMEfC0kpw9drqNJiMfQ==";
        String s = AlipayEncrypt.encryptContent("17681682549", encryptType, publicKey1, charset);
        System.out.println("s = " + s);
        String s2 = AlipayEncrypt.decryptContent(s, encryptType, publicKey1, charset);
        System.out.println("s2 = " + s2);


        String sss = "MdfC1q4gGs/I+SSrEXPj53glFjQhASHV2Op69KeecJ6iM0jN6mUVkjAOHSrjCzd9O5RI0vZt7EFcyyQP3YS5Mg==";
        String s1 = AlipayEncrypt.decryptContent(sss, encryptType, publicKey1, charset);
        System.out.println("s1 = " + s1);

    }

}
