Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

对于没有固定公网IP出口的场景,通过添加代理解决企业微信可信IP的问题 #40

Open
cjpjxjx opened this issue Jan 15, 2024 · 0 comments

Comments

@cjpjxjx
Copy link

cjpjxjx commented Jan 15, 2024

由于现在企业微信应用强制必须配置可信IP,但公司又没有固定公网IP出口的专线,都是动态公网IP,导致出口IP变化之后无法使用企业微信OAuth2认证重置密码,每次IP变化都必须手动在企业微信管理后台修改可信IP,虽然有固定公网IP的云服务器,但考虑到把程序部署到云服务器的话又无法直接访问到内网的域控,操作起来更复杂,在多次考虑和尝试之后决定使用正向代理的方式比较简单

需要有一台固定公网IP的云服务器,在上面搭建 Squid 代理(或其他),我是根据这个教程搭建(一定要加密防止被扫):docker一键安装http代理服务器squid

修改程序的 utils/wework_api/abstract_api.py 文件,在开头的 class 前面添加代理信息:

# 代理服务器
proxy = {
    'http': 'http://username:[email protected]:port',
    'https': 'http://username:[email protected]:port'
}

然后往下找到 http_post 和 http_get 定义,在 requests 参数里使用代理 proxies=proxy

    def __http_post(self, url, args):
        real_url = self.__append_token(url)

        if DEBUG is True:
            print(real_url, args)

        return requests.post(real_url, proxies=proxy, data=json.dumps(args, ensure_ascii=False).encode('utf-8')).json()

    def __http_get(self, url):
        real_url = self.__append_token(url)

        if DEBUG is True:
            print(real_url)

        return requests.get(real_url, proxies=proxy).json()

最后直接重启服务器就可以了,这样程序就会通过代理使用云服务器的IP去访问企业微信的接口,将云服务器的IP加入到可信IP里即可

有同样需求的可以尝试这个操作,希望作者后续也能考虑添加一个代理选项,我只会点三脚猫功夫就只会手动改改代码了

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant