关于java:微信商城开源版二次开发一

5次阅读

共计 2863 个字符,预计需要花费 8 分钟才能阅读完成。

微信商城开源版二次开发(一)

最近想理解如何 Java 对接微信平台,疾速搭建残缺我的项目开发,发现网上有很对开源的这类二开源码。https://gitee.com/luozijing12… 就是其中一个,介绍能够关上网页自行查看,上面介绍了该我的项目如何对接微信公众号和部署。

上面是我本人在云服务器上利用 docker 疾速部署的 http://81.69.254.72/index。

如何对接和配置微信公众号平台和微信小程序?

疾速的化能够申请测试公共号,https://developers.weixin.qq….(微信公众号开发文档),申请测试账号,获取 appid 和密钥。

通过公网认证,非公网本地 windows 认证的话能够用 ngrok-stable-windows-amd64 软件来认证,ngrok http 7500。将 windows ip:7500 通过反向代理映射到公网,来和微信平台进行认证对接,微信平台的对接实质也是账户明码的对接,不过是服务端的对接形式。后续微信接口的调用须要获取微信认证的令牌来进行接口认证调用。

因为微信接口时 https 的,本地调用时走的是 ngrok http 代理,在 SSL 层认证传递公钥时须要认证证书,这时候能够去浏览器上将微信平台给浏览器的证书下载,存到本地,与 SSL 平安证书导入打交道,把证书导入 java 的 cacerts 证书库,上面时导入本地 java 的认证语句,这样本地在调微信公众号接口时就能够带上证书的去通信了。

E:\javaDevTools\java-se-8u41-ri\bin\keytool -importcert -trustcacerts -file "E:\payLearning\wxcerts.cer" -alias ca_alias -keystore "E:\javaDevTools\java-se-8u41-ri\jre\lib\security\cacerts" -storepass changeit

微信小程序的须要下载微信开发小程序平台将前端代码编译上传至小程序平台,当作测试包应用,因为小程序须要对接 https 的服务,意味着你须要申请域名对应的认证证书,此过程比拟久,所以小程序对接的后端性能临时未去做对接。

如何在云服务器上部署?

nginx docker 部署

docker pull nginx
mkdir -p /data/nginx;
mkdir -p /data/nginx/www;
mkdir -p /data/nginx/conf;
mkdir -p /data/nginx/logs;

rm -rf /data/nginx;
rm -rf /data/nginx/www;
rm -rf /data/nginx/conf;
rm -rf //data/nginx/logs;
docker run --name nginx -p 80:80 -d nginx
#删除镜像后反向拷贝文件
docker cp 2053b13fb398:/etc/nginx/nginx.conf /data/nginx/;
docker cp 2053b13fb398:/etc/nginx/conf.d /data/nginx/conf/;
docker cp 2053b13fb398:/usr/share/nginx/html/ /data/nginx/www/dist;
docker cp 2053b13fb398:/var/log/nginx/ /data/nginx/logs/;
#启动
docker run --name nginx -p 80:80 -v /data/nginx/nginx.conf:/etc/nginx/nginx.conf -v /data/nginx/www/dist:/usr/share/nginx/html/ -v /data/nginx/logs/:/var/log/nginx/ -v /data/nginx/conf/conf.d:/etc/nginx/conf.d --privileged=true -d nginx

docker exec -it nginx /bin/bash

nginx 配置文件

server {
    listen       80;
    listen  [::]:80;

    server_name  localhost;

    location / {
        root   /usr/share/nginx/html;
        try_files $uri $uri/ /index.html;
        index index.jsp index.html index.htm;
    }

    #后盾反向代理接口地址  /prod-api/ 为前端固定生产门路 
    location /prod-api/ {
       proxy_pass http://81.69.254.72:7500/;
       proxy_connect_timeout 15s;
       proxy_send_timeout 15s;
       proxy_read_timeout 15s;
       proxy_set_header X-Real-IP $remote_addr;
       proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }
}

java pom 文件加上 docker 部署插件

<plugin>
    <groupId>com.spotify</groupId>
    <artifactId>docker-maven-plugin</artifactId>
    <version>${docker.maven.plugin.version}</version>
    <executions>
        <execution>
            <id>build-image</id>
            <phase>package</phase>
            <goals>
                <goal>build</goal>
            </goals>
        </execution>
    </executions>
    <configuration>
        <imageName>wx-${project.artifactId}:${project.version}</imageName>
        <dockerHost>${docker.host}</dockerHost>
        <baseImage>java:8</baseImage>
        <entryPoint>["java", "-jar", "-Xms256m", "-Xmx512m", "-Xmn128m","/${project.build.finalName}.jar"]
        </entryPoint>
        <resources>
            <resource>
                <targetPath>/</targetPath>
                <directory>${project.build.directory}</directory>
                <include>${project.build.finalName}.jar</include>
            </resource>
        </resources>
    </configuration>
</plugin>

前期就是将前端的包打包放入对应的 nginx 文件地位以及启动 java 容器便能够失常拜访。

前面将讲述如何具体二开平台实现的代码和性能

正文完
 0