You can not select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
			
				
					
					
						
							62 lines
						
					
					
						
							2.0 KiB
						
					
					
				
			
		
		
	
	
							62 lines
						
					
					
						
							2.0 KiB
						
					
					
				package com.ynxbd.common.action;
 | 
						|
 | 
						|
 | 
						|
import com.ynxbd.common.action.base.BaseAction;
 | 
						|
import com.ynxbd.common.helper.common.QRCodeHelper;
 | 
						|
import com.ynxbd.common.helper.common.RSAHelper;
 | 
						|
import com.ynxbd.common.result.Result;
 | 
						|
import com.ynxbd.wx.config.WeChatConfig;
 | 
						|
import lombok.extern.slf4j.Slf4j;
 | 
						|
import org.apache.struts2.convention.annotation.Action;
 | 
						|
import org.apache.struts2.convention.annotation.Namespace;
 | 
						|
 | 
						|
import java.util.HashMap;
 | 
						|
import java.util.Map;
 | 
						|
import java.util.UUID;
 | 
						|
 | 
						|
/**
 | 
						|
 * @Author wsq
 | 
						|
 * @Date 2021/1/7 17:26
 | 
						|
 * @Copyright @ 2020 云南新八达科技有限公司 All rights reserved.
 | 
						|
 */
 | 
						|
@Slf4j
 | 
						|
@Namespace("/qrCode")
 | 
						|
public class QRAction extends BaseAction {
 | 
						|
 | 
						|
    @Action("qrCodeLogin")
 | 
						|
    public Result qrCodeLogin() {
 | 
						|
        String msgInterface = getString("msgInterface");
 | 
						|
        if (msgInterface == null) {
 | 
						|
            msgInterface = "bind";
 | 
						|
        }
 | 
						|
 | 
						|
        StringBuffer url = request.getRequestURL();
 | 
						|
        String baseURL = url.delete(url.length() - request.getRequestURI().length(), url.length()).append(request.getServletContext().getContextPath()).append("/").toString();
 | 
						|
 | 
						|
        String sid = UUID.randomUUID().toString().replace("-", "");
 | 
						|
 | 
						|
        String base64 = QRCodeHelper.encodeToBase64(baseURL + WeChatConfig.getWebPath(false, true) + String.format("qr-login.html?msgInterface=%s&sid=%s", msgInterface, sid), 140, 140);
 | 
						|
 | 
						|
        Map<String, String> map = new HashMap<>();
 | 
						|
 | 
						|
        int i = baseURL.indexOf("/wx/");
 | 
						|
        if (i > 0) {
 | 
						|
            baseURL = baseURL.substring(0, i);
 | 
						|
        }
 | 
						|
 | 
						|
        if (baseURL.indexOf("http://") == 0) {
 | 
						|
            baseURL = baseURL.substring(7);
 | 
						|
        }
 | 
						|
 | 
						|
        if (baseURL.indexOf("https://") == 0) {
 | 
						|
            baseURL = baseURL.substring(8);
 | 
						|
        }
 | 
						|
 | 
						|
        map.put("domainName", baseURL);
 | 
						|
        map.put("qrCode", base64);
 | 
						|
        map.put("sid", sid);
 | 
						|
        map.put("publicKey", RSAHelper.getPublicKey());
 | 
						|
        return Result.success(map);
 | 
						|
    }
 | 
						|
 | 
						|
}
 | 
						|
 |