### Start MicroCommunity Frontend Application Source: https://github.com/java110/microcommunity/blob/master/docs/installHcDev.md Commands to start the frontend application using npm and the expected console output indicating successful startup. ```Shell Script npm start PS C:\project\vip\MicroCommunityWeb> npm start > micrcommunityweb@0.0.0 start C:\project\vip\MicroCommunityWeb > node ./bin/www ``` -------------------------------- ### Start MicroCommunity Web Frontend Source: https://github.com/java110/microcommunity/blob/master/docs/installHcDev_en.md Execute 'npm start' command to launch the MicroCommunity web frontend application. A successful startup is indicated by the output showing the 'node ./bin/www' command. ```Shell Script npm start ``` -------------------------------- ### Clone MicroCommunity Backend and Build with Maven Source: https://github.com/java110/microcommunity/blob/master/docs/installHcDev.md Instructions to clone the backend repository from Gitee and build it using Maven commands for packaging and installation. ```Shell Script git clone https://gitee.com/wuxw7/MicroCommunity.git mvn clean package mvn clean install ``` -------------------------------- ### Clone MicroCommunity Frontend Repository Source: https://github.com/java110/microcommunity/blob/master/docs/installHcDev.md Instructions to clone the frontend repository for the MicroCommunity system from Gitee. ```Shell Script git clone https://gitee.com/java110/MicroCommunityWeb.git ``` -------------------------------- ### Configure Frontend Proxy in app.js Source: https://github.com/java110/microcommunity/blob/master/docs/installHcDev.md JavaScript code snippet showing how to configure proxy routes in the frontend's app.js file to redirect requests to the backend IP address. ```JavaScript app.use('/callComponent', proxy('http://192.168.100.108:8008', opts)); app.use('/app', proxy('http://192.168.100.108:8008', opts)); ``` -------------------------------- ### Start Spring Cloud Microservices Source: https://github.com/java110/microcommunity/blob/master/如何切换为springcloud方式启动.md Launch each Spring Cloud service, identified by names starting with 'service-', using the `java -jar` command. Replace the asterisk with the specific service name to start its JAR file located in the `target` directory. ```Shell java -jar service-*\target\service-*.jar ``` -------------------------------- ### Clone and Build MicroCommunity Backend Source: https://github.com/java110/microcommunity/blob/master/docs/installHcDev_en.md Instructions to download the MicroCommunity backend source code from GitHub and build it using Maven, preparing it for deployment. ```Shell Script git clone https://github.com/java110/MicroCommunity.git mvn clean package mvn clean install ``` -------------------------------- ### Configure Jedis Redis Pool in application-dev.yml Source: https://github.com/java110/microcommunity/blob/master/docs/installHcDev.md YAML configuration for the Jedis connection pool within the application-dev.yml file, specifying Redis host, port, timeout, and a placeholder for the password. ```YAML jedis: pool: config: maxTotal: 100 maxIdle: 20 maxWaitMillis: 20000 host: dev.redis.java110.com port: 6379 timeout: 3000 password: hc ``` -------------------------------- ### Clone MicroCommunity Web Frontend Source: https://github.com/java110/microcommunity/blob/master/docs/installHcDev_en.md Instructions to download the MicroCommunity web frontend source code from GitHub, preparing it for local development. ```Shell Script git clone https://github.com/java110/MicroCommunityWeb.git ``` -------------------------------- ### Starting MicroCommunity Spring Boot Service Source: https://github.com/java110/microcommunity/blob/master/如何切换为springboot方式启动.md Once compiled, the Spring Boot service can be started. Only the 'springboot' service needs to be run, as other services are integrated into it. Two methods are provided for starting the application. ```Shell java -jar springboot\target\MicroCommunityBoot.jar ``` ```Java BootApplicationStart.java ``` -------------------------------- ### Configure MySQL Data Sources in dataSource.yml Source: https://github.com/java110/microcommunity/blob/master/docs/installHcDev.md YAML configuration for two Druid data sources (hc_community and TT databases), including JDBC URL, username, password, and connection pool settings for MySQL. ```YAML dataSources: ds0: !!com.alibaba.druid.pool.DruidDataSource driverClassName: com.mysql.cj.jdbc.Driver url: jdbc:mysql://dev.db.java110.com:3306/hc_community?useUnicode=true&characterEncoding=utf-8&serverTimezone=GMT%2B8 username: hc_community password: hc_community@12345678 minIdle: 5 validationQuery: SELECT 1 FROM DUAL initialSize: 5 maxWait: 60000 filters: stat,wall,log4j poolPreparedStatements: true ds1: !!com.alibaba.druid.pool.DruidDataSource driverClassName: com.mysql.cj.jdbc.Driver url: jdbc:mysql://dev.db.java110.com:3306/TT?useUnicode=true&characterEncoding=utf-8&serverTimezone=GMT%2B8 username: TT password: TT@12345678 minIdle: 5 validationQuery: SELECT 1 FROM DUAL initialSize: 5 maxWait: 60000 filters: stat,wall,log4j poolPreparedStatements: true ``` -------------------------------- ### Configure Spring Redis Properties in application-dev.yml Source: https://github.com/java110/microcommunity/blob/master/docs/installHcDev.md YAML configuration for Spring application properties, including HTTP encoding, application name, and detailed Redis connection settings with a password placeholder. ```YAML spring: profiles: active: share http: encoding: charset: UTF-8 enabled: true force: true application: name: community-service redis: database: 0 host: dev.redis.java110.com port: 6379 password: hc pool: max-active: 300 max-wait: 10000 max-idle: 100 min-idle: 0 timeout: 0 ``` -------------------------------- ### Configure Hosts File for MicroCommunity Services Source: https://github.com/java110/microcommunity/blob/master/docs/installHcDev.md Add local DNS entries to the hosts file to map service domains to the localhost IP address, essential for inter-service communication and API access. ```Hosts File Configuration 127.0.0.1 dev.db.java110.com 127.0.0.1 dev.zk.java110.com 127.0.0.1 dev.kafka.java110.com 127.0.0.1 dev.redis.java110.com 127.0.0.1 api.java110.com 127.0.0.1 dev.java110.com ``` -------------------------------- ### Configure Local Hosts File for MicroCommunity Services Source: https://github.com/java110/microcommunity/blob/master/docs/installHcDev_en.md Add these entries to your local hosts file (e.g., /etc/hosts or C:\Windows\System32\drivers\etc\hosts) to map service domain names to localhost, enabling proper communication within the development environment. ```Text 127.0.0.1 dev.db.java110.com 127.0.0.1 dev.zk.java110.com 127.0.0.1 dev.kafka.java110.com 127.0.0.1 dev.redis.java110.com 127.0.0.1 api.java110.com 127.0.0.1 dev.java110.com ``` -------------------------------- ### Example Maven Dependencies for Banking and Utility Libraries Source: https://github.com/java110/microcommunity/blob/master/service-acct/readme.md This snippet contains commented-out Maven declarations. It showcases dependencies for ICBC banking SDKs, the `hutool-all` library (often used in Chinese banking contexts like Pudong Development Bank), and the `bcprov-jdk15to18` Bouncy Castle cryptographic provider. These examples illustrate common third-party integrations in Java projects. ```XML ``` -------------------------------- ### Running Environment Switch Script for Spring Boot Source: https://github.com/java110/microcommunity/blob/master/如何切换为springboot方式启动.md Before compiling and starting the Spring Boot service, run the appropriate script to modify the project's POM file. This script transfers the content of 'pom-boot.xml' from the service directory into the main 'pom.xml'. ```Batch changeBootEnvWindow.bat ``` ```Shell changeBootEnvLinux.sh ``` -------------------------------- ### Run Kafka Container with Docker Source: https://github.com/java110/microcommunity/blob/master/java110-interface/docker/kafka/execute.txt Starts a new Docker container named 'kafka_test' from the wurstmeister/kafka:latest image. It runs in detached interactive mode (-idt) and maps Zookeeper's default port (2181) and Kafka's default port (9092) from the container to the host machine, making them accessible. ```docker docker run -ti --name kafka_test -p2181:2181 -p9092:9092 -idt wurstmeister/kafka:latest ``` -------------------------------- ### Monitor Kafka Container Logs Source: https://github.com/java110/microcommunity/blob/master/java110-interface/docker/kafka/execute.txt Streams the logs from the 'kafka_test' Docker container in real-time. This command is useful for monitoring the container's startup process, checking for errors, and observing ongoing operations of the Kafka instance. ```docker docker logs -f kafka_test ``` -------------------------------- ### Configure Frontend Proxy in app.js Source: https://github.com/java110/microcommunity/blob/master/docs/installHcDev_en.md Modify the 'app.js' file in the frontend project to configure proxy routes for backend API calls. Update the IP address '192.168.100.108' to match the actual IP of your backend server. ```JavaScript app.use('/callComponent', proxy('http://192.168.100.108:8008', opts)); app.use('/app', proxy('http://192.168.100.108:8008', opts)); ``` -------------------------------- ### Configure Spring Redis in application-dev.yml Source: https://github.com/java110/microcommunity/blob/master/docs/installHcDev_en.md YAML configuration for Spring's Redis integration, including database selection, host, port, password, and connection pool settings. The 'password' field needs to be updated to your Redis password. ```YAML spring: profiles: active: share http: encoding: charset: UTF-8 enabled: true force: true application: name: community-service redis: database: 0 host: dev.redis.java110.com port: 6379 password: hc pool: max-active: 300 max-wait: 10000 max-idle: 100 min-idle: 0 timeout: 0 ``` -------------------------------- ### Configure MySQL Data Sources in dataSource.yml Source: https://github.com/java110/microcommunity/blob/master/docs/installHcDev_en.md YAML configuration for two MySQL data sources (ds0 for hc_community and ds1 for TT), specifying driver, URL, username, password, and connection pool properties. Passwords for both data sources must be updated. ```YAML dataSources: ds0: !!com.alibaba.druid.pool.DruidDataSource driverClassName: com.mysql.cj.jdbc.Driver url: jdbc:mysql://dev.db.java110.com:3306/hc_community?useUnicode=true&characterEncoding=utf-8&serverTimezone=GMT%2B8 username: hc_community password: hc_community@12345678 minIdle: 5 validationQuery: SELECT 1 FROM DUAL initialSize: 5 maxWait: 60000 filters: stat,wall,log4j poolPreparedStatements: true ds1: !!com.alibaba.druid.pool.DruidDataSource driverClassName: com.mysql.cj.jdbc.Driver url: jdbc:mysql://dev.db.java110.com:3306/TT?useUnicode=true&characterEncoding=utf-8&serverTimezone=GMT%2B8 username: TT password: TT@12345678 minIdle: 5 validationQuery: SELECT 1 FROM DUAL initialSize: 5 maxWait: 60000 filters: stat,wall,log4j poolPreparedStatements: true ``` -------------------------------- ### Pull Kafka Docker Image Source: https://github.com/java110/microcommunity/blob/master/java110-interface/docker/kafka/execute.txt Pulls the latest wurstmeister/kafka Docker image from Docker Hub. This command ensures that the necessary image is available locally before attempting to run a container from it. ```docker docker pull wurstmeister/kafka ``` -------------------------------- ### Configure Redis Jedis Pool in application-dev.yml Source: https://github.com/java110/microcommunity/blob/master/docs/installHcDev_en.md YAML configuration for the Jedis connection pool, specifying host, port, timeout, and password for Redis connectivity within the application. The 'password' field should be updated to match your Redis instance's password. ```YAML jedis: pool: config: maxTotal: 100 maxIdle: 20 maxWaitMillis: 20000 host: dev.redis.java110.com port: 6379 timeout: 3000 password: hc ``` -------------------------------- ### Maven Dependencies for ICBC Payment SDK Source: https://github.com/java110/microcommunity/blob/master/service-acct/src/main/java/com/java110/acct/payment/adapt/icbc/IcbcPaymentFactoryAdapt.java.txt Instructions and XML snippets for adding the necessary ICBC API SDK JARs to the project's `pom.xml` file. These dependencies are crucial for compiling and running the ICBC payment adapter. Users must manually install these JARs into their private Maven repository. ```XML com.icbc icbc-api-sdk-cop v1.0 com.icbc icbc-api-sdk-cop-io v1.0 com.icbc icbc-ca v1.0 ``` -------------------------------- ### ICBC Payment Processing Method Signature and Initial Setup Source: https://github.com/java110/microcommunity/blob/master/service-acct/src/main/java/com/java110/acct/payment/adapt/icbc/IcbcPaymentFactoryAdapt.java.txt The core `java110Payment` method, overriding the `IPaymentFactoryAdapt` interface, initiates the payment process. It retrieves WeChat details, application ID, user ID, trade type, and constructs the notification URL. It also handles the retrieval of `openId` based on the application type, which is crucial for different WeChat payment scenarios. ```Java @Override public Map java110Payment(PaymentOrderDto paymentOrderDto, JSONObject reqJson, ICmdDataFlowContext context) throws Exception { SmallWeChatDto smallWeChatDto = getSmallWechat(reqJson); String appId = context.getReqHeaders().get("app-id"); String userId = context.getReqHeaders().get("user-id"); String tradeType = reqJson.getString("tradeType"); String notifyUrl = UrlCache.getOwnerUrl() + "/app/payment/notify/icbc/992020011134400001"; String openId = reqJson.getString("openId"); if (StringUtil.isEmpty(openId)) { String appType = OwnerAppUserDto.APP_TYPE_WECHAT_MINA; if (AppDto.WECHAT_OWNER_APP_ID.equals(appId)) { appType = OwnerAppUserDto.APP_TYPE_WECHAT; } else if (AppDto.WECHAT_MINA_OWNER_APP_ID.equals(appId)) { appType = OwnerAppUserDto.APP_TYPE_WECHAT_MINA; } else { appType = OwnerAppUserDto.APP_TYPE_APP; } ``` -------------------------------- ### Manage Redis Container Lifecycle with Docker Source: https://github.com/java110/microcommunity/blob/master/java110-interface/docker/redis/execute.txt This snippet provides a sequence of Docker commands to pull the official Redis image, run a new Redis container named 'redis_test' mapping port 6379, and then continuously stream its logs. This allows for quick setup and basic monitoring of a Redis instance. ```docker docker pull redis docker run -ti --name redis_test -p6379:6379 -idt redis:latest docker logs -f redis_test ``` -------------------------------- ### Execute Command Inside Docker Container Source: https://github.com/java110/microcommunity/blob/master/java110-interface/docker/mysql/execute.txt This command executes an interactive Bash shell inside the running 'mysql_test' Docker container. This allows direct access to the container's environment, file system, and installed utilities for troubleshooting or configuration. ```Shell docker exec -it mysql_test /bin/bash ``` -------------------------------- ### Measure Spring Bean Initialization Time in Java Source: https://github.com/java110/microcommunity/blob/master/java110-db/src/main/java/com/java110/db/BeanInitCostTimeBeanPostProcessor.java.txt This Spring component implements `BeanPostProcessor` to track the time taken for each bean to initialize. It records the start time before initialization and calculates the duration after initialization. If a bean's initialization time exceeds 1000 milliseconds (1 second), its name and cost time are printed to the console, aiding in performance tuning and identifying slow-loading beans. ```Java package com.java110.db; import org.springframework.beans.BeansException; import org.springframework.beans.factory.config.BeanPostProcessor; import org.springframework.stereotype.Component; import java.util.Map; import java.util.Objects; import java.util.concurrent.ConcurrentHashMap; /** * 此类主要用于调优,使用 打印bean的加载时间 */ @Component public class BeanInitCostTimeBeanPostProcessor implements BeanPostProcessor { private static Map startTime = new ConcurrentHashMap<>(); @Override public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException { startTime.put(beanName, System.currentTimeMillis()); return bean; } @Override public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException { if (Objects.nonNull(startTime.get(beanName))) { long time = System.currentTimeMillis() - startTime.get(beanName); if(time>1000) { System.out.println("beanName=" + beanName + ",costTime=" + time); } } return bean; } } ``` -------------------------------- ### Process ICBC QR Code Scanned Payment Request in Java Source: https://github.com/java110/microcommunity/blob/master/service-acct/src/main/java/com/java110/acct/smo/impl/QrCodeIcbcPaymentAdapt.java.txt This Java snippet initiates a QR code scanned payment request using the ICBC API. It configures terminal information, sets business content (e.g., subject, goods details, though commented out in this example), and executes the payment request. The method handles successful responses and API exceptions, returning a `ResultVo` indicating the transaction's outcome. ```Java //bizContent.setGoodsTag("DP"); //优惠标志 // JSONArray goodsDetailArray = new JSONArray(); // JSONObject gd1 = new JSONObject(); // gd1.put("goods_id", "123456"); // gd1.put("goods_name", "FOOD"); // gd1.put("quantity", 1); // gd1.put("price", 100); // goodsDetailArray.add(gd1); // bizContent.setGoodsDetail(goodsDetailArray); // bizContent.setSubject("订单标题,128字节长度"); //订单标题,128字节长度 HashMap terminalInfo = new HashMap<>(); terminalInfo.put("device_type", "10"); terminalInfo.put("device_id", deciveInfo);//| device_id | str | true | 15 | 终端设备号: 收单机构为商户终端分配的唯一编号。 | Sxxxxxx | bizContent.setTerminalInfo(terminalInfo); request.setBizContent(bizContent); MybankQrcodeScannedPayResponseV5 response; try { response = client.execute(request, System.currentTimeMillis() + "");//msgId消息通讯唯一编号,要求每次调用独立生成,APP级唯一 if (response.getReturnCode() == 0) { // 6、业务成功处理,请根据接口文档用response.getxxx()获取同步返回的业务数据 return new ResultVo(ResultVo.CODE_OK, "成功"); } else { // 失败 //System.out.println("ReturnCode:"+response.getReturnCode()); //System.out.println("ReturnMsg:"+response.getReturnMsg()); return new ResultVo(ResultVo.CODE_ERROR, response.getReturnMsg()); } } catch (IcbcApiException e) { e.printStackTrace(); } return new ResultVo(ResultVo.CODE_ERROR, "未知异常"); ``` -------------------------------- ### Compile and Package Spring Cloud Project Source: https://github.com/java110/microcommunity/blob/master/如何切换为springcloud方式启动.md After switching the environment, compile and package the project using Maven to prepare for deployment. This ensures all dependencies are resolved and the project is built into executable JARs. ```Shell mvn clean install ``` ```Shell mvn clean package ``` -------------------------------- ### Execute Spring Cloud Environment Switch Script Source: https://github.com/java110/microcommunity/blob/master/如何切换为springcloud方式启动.md Run the appropriate script to modify the project's `pom.xml` for Spring Cloud integration. This script transfers content from `pom-cloud.xml` to `pom.xml`. Use `changeCloudEnvWindow.bat` for Windows or `changeCloudEnvLinux.sh` for macOS/Linux. ```Batch changeCloudEnvWindow.bat ``` ```Shell changeCloudEnvLinux.sh ``` -------------------------------- ### Compiling MicroCommunity Project for Spring Boot Source: https://github.com/java110/microcommunity/blob/master/如何切换为springboot方式启动.md After running the environment switch script, compile the project using Maven. This step builds the necessary artifacts for the Spring Boot service. ```Maven mvn clean install mvn clean package ``` -------------------------------- ### ICBC Payment Adapter Class Definition and Imports Source: https://github.com/java110/microcommunity/blob/master/service-acct/src/main/java/com/java110/acct/payment/adapt/icbc/IcbcPaymentFactoryAdapt.java.txt The main Java class `IcbcPaymentFactoryAdapt` implements `IPaymentFactoryAdapt` and handles ICBC payment logic. This snippet shows the package, import statements, and class declaration, indicating its role as a Spring service. ```Java package com.java110.acct.payment.adapt.icbc; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; import com.icbc.api.DefaultIcbcClient; import com.icbc.api.IcbcApiException; import com.icbc.api.IcbcConstants; import com.icbc.api.request.CardbusinessAggregatepayB2cOnlineConsumepurchaseRequestV1; import com.icbc.api.request.CardbusinessAggregatepayB2cOnlineConsumepurchaseRequestV1.CardbusinessAggregatepayB2cOnlineConsumepurchaseRequestV1Biz; import com.icbc.api.response.CardbusinessAggregatepayB2cOnlineConsumepurchaseResponseV1; import com.icbc.api.utils.IcbcEncrypt; import com.icbc.api.utils.IcbcSignature; import com.icbc.api.utils.WebUtils; import com.java110.acct.payment.IPaymentFactoryAdapt; import com.java110.acct.payment.adapt.plutus.PlutusPaymentFactoryAdapt; import com.java110.core.context.ICmdDataFlowContext; import com.java110.core.factory.CommunitySettingFactory; import com.java110.core.factory.WechatFactory; import com.java110.core.log.LoggerFactory; import com.java110.dto.app.AppDto; import com.java110.dto.owner.OwnerAppUserDto; import com.java110.dto.payment.PaymentOrderDto; import com.java110.dto.wechat.SmallWeChatDto; import com.java110.intf.store.ISmallWechatV1InnerServiceSMO; import com.java110.intf.user.IOwnerAppUserInnerServiceSMO; import com.java110.utils.cache.CommonCache; import com.java110.utils.cache.MappingCache; import com.java110.utils.cache.UrlCache; import com.java110.utils.constant.WechatConstant; import com.java110.utils.util.BeanConvertUtil; import com.java110.utils.util.DateUtil; import com.java110.utils.util.PayUtil; import com.java110.utils.util.StringUtil; import org.slf4j.Logger; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Service; import org.springframework.web.client.RestTemplate; import java.util.*; @Service("icbcPaymentFactory") public class IcbcPaymentFactoryAdapt implements IPaymentFactoryAdapt { ``` -------------------------------- ### Query All Devices API for Property Management Source: https://github.com/java110/microcommunity/blob/master/docs/api/machine.md This API allows property management to query all devices within a specific community. It supports pagination and requires the community ID, page number, and row count as input, returning a paginated list of devices. ```APIDOC Method: GET URL: /api/machine.listMachines Request Parameters: - page (Integer, Required): Page number (Example: 1) - row (Integer, Required): Number of items per page (Example: 10) - communityId (String, Required): Community ID (Example: 2020122471920846) Response Parameters: - direction (String, Required): Entry/Exit direction (Example: 3306) - directionName (String, Required): Chinese description of direction (Example: 进场) - heartbeatTime (String, Required): Device last heartbeat time (Example: 2020-12-31 18:06:40) - locationObjId (String, Required): Location ID (Example: 2020122471920846) - locationObjName (String, Required): Location description (Example: iot_小区 位置3) - machineCode (String, Required): Device code (Example: 1368371) - machineId (String, Required): Device ID (Example: 892020122872730977) - machineIp (String, Optional): Device IP (Example: 192.168.1.1) - machineMac (String, Optional): Device MAC (Example: 11:11:11:11) - machineName (String, Required): Device name (Example: 厦门集美2) - machineTypeCd (String, Required): Represents access control (Example: 9999) - machineTypeCdName (String, Required): Device type description (Example: 门禁) ``` ```URL http://ip:port/api/machine.listMachines?communityId=2020122471920846&page=1&row=10 ``` ```JSON { "machines": [{ "direction": "3306", "directionName": "进场", "heartbeatTime": "2020-12-31 18:06:40", "locationObjId": "2020122471920846", "locationObjName": "iot_小区 位置3", "machineCode": "1368371", "machineId": "892020122872730977", "machineIp": "", "machineMac": "", "machineName": "厦门集美2", "machineTypeCd": "9999", "machineTypeCdName": "门禁" }], "page": 1, "records": 1, "rows": 1, "total": 0 } ``` -------------------------------- ### Initiate ICBC Unified Payment Order in Java Source: https://github.com/java110/microcommunity/blob/master/service-acct/src/main/java/com/java110/acct/payment/adapt/icbc/IcbcPaymentFactoryAdapt.java.txt This private method constructs and sends a unified payment request to the ICBC API. It retrieves various configuration parameters such as private key, public key, merchant ID, and application details from `CommunitySettingFactory`. It then uses `DefaultIcbcClient` to make the `CardbusinessAggregatepayB2cOnlineConsumepurchaseRequestV1` call, setting the business content for the payment. ```Java private JSONObject java110UnifieldOrder(String feeName, String orderNum, String tradeType, double payAmount, String openid, SmallWeChatDto smallWeChatDto, String notifyUrl) throws Exception { //String systemName = MappingCache.getValue(WechatConstant.WECHAT_DOMAIN, WechatConstant.PAY_GOOD_NAME); String privateKey = CommunitySettingFactory.getRemark(smallWeChatDto.getObjId(), "ICBC_PRIVATE_KEY"); String apiPublicKey = CommunitySettingFactory.getRemark(smallWeChatDto.getObjId(), "ICBC_PUBLIC_KEY"); String merId = CommunitySettingFactory.getValue(smallWeChatDto.getObjId(), "ICBC_MER_ID"); String merPrtclNo = CommunitySettingFactory.getValue(smallWeChatDto.getObjId(), "ICBC_MER_PRTCL_NO"); String deciveInfo = CommunitySettingFactory.getValue(smallWeChatDto.getObjId(), "ICBC_DECIVE_INFO"); String appName = CommunitySettingFactory.getValue(smallWeChatDto.getObjId(), "ICBC_APP_NAME"); String icbcAppId = CommunitySettingFactory.getValue(smallWeChatDto.getObjId(), "ICBC_APP_ID"); String appId = CommunitySettingFactory.getValue(smallWeChatDto.getObjId(), "APP_ID"); System.out.println("appId=" + appId); System.out.println("privateKey=" + privateKey); System.out.println("apiPublicKey=" + apiPublicKey); System.out.println("merId=" + merId); System.out.println("merPrtclNo=" + merPrtclNo); System.out.println("deciveInfo=" + deciveInfo); System.out.println("appName=" + appName); System.out.println("icbcAppId=" + icbcAppId); DefaultIcbcClient client = new DefaultIcbcClient(appId, IcbcConstants.SIGN_TYPE_RSA2, privateKey, apiPublicKey); CardbusinessAggregatepayB2cOnlineConsumepurchaseRequestV1 request = new CardbusinessAggregatepayB2cOnlineConsumepurchaseRequestV1(); //根据测试环境和生产环境替换相应ip和端口 request.setServiceUrl("https://gw.open.icbc.com.cn/api/cardbusiness/aggregatepay/b2c/online/consumepurchase/V1"); CardbusinessAggregatepayB2cOnlineConsumepurchaseRequestV1Biz bizContent = new CardbusinessAggregatepayB2cOnlineConsumepurchaseRequestV1Biz(); request.setBizContent(bizContent); //请对照接口文档用bizContent.setxxx()方法对业务上送数据进行赋值 bizContent.setMer_id(merId); bizContent.setOut_trade_no(orderNum); bizContent.setPay_mode("9"); bizContent.setAccess_type("7"); } ``` -------------------------------- ### Nginx Server Block for External API Documentation Proxy Source: https://github.com/java110/microcommunity/blob/master/java110-doc/readme.md This Nginx server block configures a virtual host (`apidoc.homecommunity.cn`) to listen on port 80. It proxies requests for `/`, `/js`, and `/css` to `http://dev.api.java110.com:8008`, specifically targeting `doc-ui.html` for the root. The `/doc` location is proxied to `http://dev.api.java110.com:8088` and includes an `Access-Control-Allow-Origin: *` header to enable cross-origin requests. ```agsl server { listen 80; server_name apidoc.homecommunity.cn; location / { proxy_pass http://dev.api.java110.com:8008/doc-ui.html; } location /js { proxy_pass http://dev.api.java110.com:8008; } location /css { proxy_pass http://dev.api.java110.com:8008; } location /doc { add_header 'Access-Control-Allow-Origin' '*'; proxy_pass http://dev.api.java110.com:8088; } } ``` -------------------------------- ### Restart Device API Source: https://github.com/java110/microcommunity/blob/master/docs/api/machine.md This API is used to restart a device from the property management web system. It requires the device code and community ID as input parameters. ```APIDOC Method: POST URL: /api/machine/restartMachine Request Parameters: - machineCode (String, Required): Device code (Example: 1368371) - communityId (String, Required): Community ID (Example: 2020122471920846) Response Parameters: - code (Integer): Status code (0 for success) - msg (String): Message (e.g., "成功" for success) - data (String): Additional data (empty on success) ``` ```JSON { "machineCode": "1368371", "communityId": "2020122471920846" } ``` ```JSON { "code":0, "msg":"成功", "data":"" } ``` -------------------------------- ### Build Docker Image for MySQL Source: https://github.com/java110/microcommunity/blob/master/java110-interface/docker/mysql/execute.txt This command builds a Docker image named 'java110/docker-mysql' from the Dockerfile located in the current directory. It's the first step to containerizing the MySQL database for the project. ```Shell docker build -t java110/docker-mysql . ``` -------------------------------- ### API: Upload Face Recognition Door Opening Log Source: https://github.com/java110/microcommunity/blob/master/docs/api/machine.md This API allows the HC IoT system to upload door opening records, specifically for face recognition events, to the property management system. It details the required parameters for the POST request, including user information, device details, opening type, and captured photo. ```APIDOC Endpoint: /api/machine/openDoorLog Method: POST Parameters: userId: String (Required) - User ID (e.g., 702020042194860037) userName: String (Required) - User Name (e.g., 张三) machineCode: String (Required) - Device Code (e.g., 101010) openTypeCd: String (Required) - Door Opening Type (1000: Face Recognition, 2000: Key) (e.g., 1000) similar: String (Required) - Opening Similarity (e.g., 100) photo: String (Required) - Captured Photo (base64 encoded) (e.g., base64,xxx) dateTime: String (Required) - Opening Time (e.g., 2020-12-27 00:00:00) extCommunityId: String (Required) - Community ID (e.g., 702020042194860039) recordTypeCd: String (Required) - Record Type (8888: Door Opening Record, 6666: Visitor Photo) (e.g., 8888) ``` ```JSON { "userId": "702020042194860037", "userName": "张三", "machineCode": "101010", "openTypeCd": "1000", "similar": "100", "photo": "base64,xxx", "dateTime": "2020-12-27 00:00:00", "extCommunityId": "702020042194860039", "recordTypeCd": "8888" } ``` ```JSON { "code":0, "msg":"成功", "data":"" } ``` -------------------------------- ### Process Unified Payment Order and Format Response in Java Source: https://github.com/java110/microcommunity/blob/master/service-acct/src/main/java/com/java110/acct/payment/adapt/icbc/IcbcPaymentFactoryAdapt.java.txt This code orchestrates the unified payment order process. It calculates the payment amount, calls an internal `java110UnifieldOrder` method to initiate the payment, and then formats the response map (`resultMap`) based on the `tradeType` (JSAPI, APP, NATIVE) to return appropriate parameters for different payment scenarios. ```Java logger.debug("【小程序支付】 统一下单开始, 订单编号=" + paymentOrderDto.getOrderId()); SortedMap resultMap = new TreeMap(); //生成支付金额,开发环境处理支付金额数到0.01、0.02、0.03元 double payAmount = PayUtil.getPayAmountByEnv(MappingCache.getValue(MappingConstant.ENV_DOMAIN,"HC_ENV"), paymentOrderDto.getMoney()); //添加或更新支付记录(参数跟进自己业务需求添加) JSONObject resMap = null; resMap = this.java110UnifieldOrder(paymentOrderDto.getName(), paymentOrderDto.getOrderId(), tradeType, payAmount, openId, smallWeChatDto, notifyUrl ); if (TRADE_TYPE_JSAPI.equals(tradeType)) { resultMap.putAll(JSONObject.toJavaObject(resMap, Map.class)); //resultMap.put("sign", resultMap.get("paySign")); resultMap.put("appId", resultMap.get("appid")); resultMap.put("timeStamp", resultMap.get("timestamp")); resultMap.put("nonceStr", resultMap.get("noncestr")); } else if (TRADE_TYPE_APP.equals(tradeType)) { resultMap.put("appId", smallWeChatDto.getAppId()); resultMap.put("timeStamp", PayUtil.getCurrentTimeStamp()); resultMap.put("nonceStr", PayUtil.makeUUID(32)); resultMap.put("partnerid", smallWeChatDto.getMchId()); resultMap.put("prepayid", resMap.getString("session_id")); //resultMap.put("signType", "MD5"); resultMap.put("sign", PayUtil.createSign(resultMap, smallWeChatDto.getPayPassword())); } else if (TRADE_TYPE_NATIVE.equals(tradeType)) { resultMap.put("prepayId", resMap.getString("session_id")); resultMap.put("codeUrl", resMap.getString("qr_code")); } resultMap.put("code", "0"); resultMap.put("msg", "下单成功"); logger.info("【小程序支付】统一下单成功,返回参数:" + resultMap); return resultMap; ``` -------------------------------- ### Configure ShardingSphere DataSource with Dynamic YAML in Spring Source: https://github.com/java110/microcommunity/blob/master/java110-db/src/main/java/com/java110/db/SharejdbcDataSourceConfig.java.txt This method creates and configures a ShardingSphere DataSource bean. It dynamically loads a `dataSource.yml` file (or a profile-specific variant) from the classpath, replaces placeholders for database credentials and connection details using environment properties, and then uses `YamlShardingDataSourceFactory` to create the data source. It handles potential SQLException and IOException during data source creation. ```Java package com.java110.db; import com.java110.utils.util.StringUtil; import org.apache.shardingsphere.shardingjdbc.api.yaml.YamlShardingDataSourceFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.core.env.Environment; import org.springframework.core.io.ClassPathResource; import org.springframework.core.io.Resource; import javax.servlet.Filter; import javax.sql.DataSource; import java.io.*; import java.sql.SQLException; /** * 数据源配置 */ @Configuration public class SharejdbcDataSourceConfig { //@Autowired private Filter statFilter; @Autowired private Environment env; private static final String SHARDING_YML_PATH = "dataSource.yml"; /** * 构建dataSource * 这里没有使用ShardingDataSourceFactory * 因为要为durid数据源配置监听Filter * * @return 数据源对象 * @throws SQLException sql异常 * @throws IOException IO 异常 * @since 1.8 */ @Bean public DataSource dataSource() throws SQLException, IOException { String path = SHARDING_YML_PATH; String[] actives = env.getActiveProfiles(); if (actives != null && actives.length > 0 && !"dev".equals(actives[0])) { path = "dataSource-" + actives[0] + ".yml"; } String configString = new String(getYmlFile(path), "UTF-8"); configString = configString.replaceAll("\\$\{mysqlpwd\\}", env.getProperty("mysqlpwd")); String mysqlPort = StringUtil.isEmpty(env.getProperty("mysqlport")) ? "3306" : env.getProperty("mysqlport"); configString = configString.replaceAll("\\$\{mysqlport\\}", mysqlPort); String dbttname = StringUtil.isEmpty(env.getProperty("dbttname")) ? "TT" : env.getProperty("dbttname"); String dbttuser = StringUtil.isEmpty(env.getProperty("dbttuser")) ? "TT" : env.getProperty("dbttuser"); String dbhcname = StringUtil.isEmpty(env.getProperty("dbhcname")) ? "hc_community" : env.getProperty("dbhcname"); String dbhcuser = StringUtil.isEmpty(env.getProperty("dbhcuser")) ? "hc_community" : env.getProperty("dbhcuser"); configString = configString.replaceAll("\\$\{dbttname\\}", dbttname) .replaceAll("\\$\{dbttuser\\}", dbttuser) .replaceAll("\\$\{dbhcname\\}", dbhcname) .replaceAll("\\$\{dbhcuser\\}", dbhcuser); return YamlShardingDataSourceFactory.createDataSource(configString.getBytes("UTF-8")); } ``` -------------------------------- ### Initiating ICBC Online Consumption Purchase in Java Source: https://github.com/java110/microcommunity/blob/master/service-acct/src/main/java/com/java110/acct/payment/adapt/icbc/IcbcPaymentFactoryAdapt.java.txt This Java code snippet demonstrates how to construct and send a B2C online consumption purchase request to the ICBC payment gateway. It populates various business content parameters such as merchant protocol number, order details, total fee, and notification URL, then executes the request and processes the synchronous response. ```Java bizContent.setMer_prtcl_no(merPrtclNo); bizContent.setOrig_date_time(DateUtil.getNow(DateUtil.DATE_FORMATE_STRING_E).replace("Z", "")); bizContent.setDecive_info(deciveInfo); bizContent.setBody(appName + "-购买商品"); bizContent.setFee_type("001"); bizContent.setSpbill_create_ip("192.168.1.8"); bizContent.setTotal_fee(PayUtil.moneyToIntegerStr(payAmount)); bizContent.setMer_url(notifyUrl); bizContent.setShop_appid(smallWeChatDto.getAppId()); bizContent.setIcbc_appid(icbcAppId); bizContent.setOpen_id(openid); // bizContent.setMer_acct("6212880200000038618"); bizContent.setExpire_time("120"); //bizContent.setNotify_type("HS"); bizContent.setNotify_type("HS"); bizContent.setResult_type("1"); bizContent.setPay_limit("no_credit"); bizContent.setOrder_apd_inf(""); CardbusinessAggregatepayB2cOnlineConsumepurchaseResponseV1 response; System.out.println("request:" + JSON.toJSONString(request)); response = client.execute(request, System.currentTimeMillis() + "");//msgId消息通讯唯一编号,要求每次调用独立生成,APP级唯一 if (response.getReturnCode() == 0) { // 6、业务成功处理,请根据接口文档用response.getxxx()获取同步返回的业务数据 System.out.println("ReturnCode:" + response.getReturnCode()); System.out.println("response:" + JSON.toJSONString(response)); CommonCache.setValue("icbc_"+icbcAppId,smallWeChatDto.getAppId(),CommonCache.PAY_DEFAULT_EXPIRE_TIME); CommonCache.setValue("icbc_community_"+icbcAppId,smallWeChatDto.getObjId(),CommonCache.PAY_DEFAULT_EXPIRE_TIME); return JSONObject.parseObject(response.getWx_data_package()); } else { // 失败 System.out.println("ReturnMsg:" + response.getReturnMsg()); throw new IllegalArgumentException("支付失败" + response.getReturnMsg()); } ``` -------------------------------- ### API: Provide Feedback on IoT Command Execution Results Source: https://github.com/java110/microcommunity/blob/master/docs/api/machine.md This API is used by the IoT system to asynchronously report the results of command executions, especially when using MQTT protocol or asynchronous interactions. It requires configuration on the IoT system side to specify the feedback address. ```APIDOC Endpoint: /api/machine/cmdResult Method: POST Parameters: taskId: String (Required) - Task ID, passed when third-party system calls results (e.g., 702020042194860037) code: Integer (Required) - Command execution status code (0: Success, Others: Failure) (e.g., 0) msg: String (Required) - Command execution description (e.g., 成功) ``` ```JSON { "taskId": "702020042194860037", "code": 0, "msg": "成功" } ``` ```JSON { "code":0, "msg":"成功", "data":"" } ``` -------------------------------- ### View Docker Container Logs Source: https://github.com/java110/microcommunity/blob/master/java110-interface/docker/mysql/execute.txt This command streams the logs of the 'mysql_test' Docker container in real-time. It's useful for monitoring the container's startup process, database activity, and for debugging any issues. ```Shell docker logs -f mysql_test ``` -------------------------------- ### Initiate ICBC QR Code Scanned Payment in Java Source: https://github.com/java110/microcommunity/blob/master/service-acct/src/main/java/com/java110/acct/smo/impl/QrCodeIcbcPaymentAdapt.java.txt This snippet demonstrates how to initiate a QR code scanned payment using the ICBC Open API in Java. It configures the `DefaultIcbcClient` with application ID, private key, and public key, then constructs a `MybankPayQrcodeScannedPayRequestV5` with essential business parameters like merchant ID, QR code, order number, trade date/time, and order amount. The `payAmount` is adjusted based on the environment, and various merchant-specific details are retrieved from configuration. ```Java @Override public ResultVo pay(String communityId, String orderNum, double money, String authCode, String feeName) throws Exception { logger.info("【工商银行支付】 统一下单开始, 订单编号=" + orderNum); SortedMap resultMap = new TreeMap(); //生成支付金额,开发环境处理支付金额数到0.01、0.02、0.03元 // double payAmount = PayUtil.getPayAmountByEnv(MappingCache.getValue(MappingConstant.ENV_DOMAIN,"HC_ENV"), money); double payAmount = PayUtil.getPayAmountByEnv(MappingCache.getValue("HC_ENV"), money); //添加或更新支付记录(参数跟进自己业务需求添加) String systemName = MappingCache.getValue(WechatConstant.WECHAT_DOMAIN, WechatConstant.PAY_GOOD_NAME); String privateKey = CommunitySettingFactory.getRemark(communityId, "ICBC_PRIVATE_KEY"); String apiPublicKey = CommunitySettingFactory.getRemark(communityId, "ICBC_PUBLIC_KEY"); String merId = CommunitySettingFactory.getValue(communityId, "ICBC_MER_ID"); String merPrtclNo = CommunitySettingFactory.getValue(communityId, "ICBC_MER_PRTCL_NO"); String deciveInfo = CommunitySettingFactory.getValue(communityId, "ICBC_DECIVE_INFO"); String appName = CommunitySettingFactory.getValue(communityId, "ICBC_APP_NAME"); String icbcAppId = CommunitySettingFactory.getValue(communityId, "ICBC_APP_ID"); //System.out.println("appId=" + appId); System.out.println("privateKey=" + privateKey); System.out.println("apiPublicKey=" + apiPublicKey); System.out.println("merId=" + merId); System.out.println("merPrtclNo=" + merPrtclNo); System.out.println("deciveInfo=" + deciveInfo); System.out.println("appName=" + appName); System.out.println("icbcAppId=" + icbcAppId); //签名类型为RSA2时,需传入appid,私钥和网关公钥,签名类型使用定值IcbcConstants.SIGN_TYPE_RSA2,其他参数使用缺省值 DefaultIcbcClient client = new DefaultIcbcClient(icbcAppId, IcbcConstants.SIGN_TYPE_RSA2, privateKey, apiPublicKey); MybankPayQrcodeScannedPayRequestV5 request = new MybankPayQrcodeScannedPayRequestV5(); //4、根据测试环境和生产环境替换相应ip和端口 request.setServiceUrl("https://gw.open.icbc.com.cn/api/mybank/pay/qrcode/scanned/pay/V5"); //5、请对照接口文档用bizContent.setxxx()方法对业务上送数据进行赋值 MybankPayQrcodeScannedPayRequestV5Biz bizContent = new MybankPayQrcodeScannedPayRequestV5Biz(); bizContent.setMerId(merId); //商户编号 bizContent.setQrCode(authCode); //付款码 bizContent.setOutTradeNo(orderNum); //外部订单号 bizContent.setTradeDate(DateUtil.getNow(DateUtil.DATE_FORMATE_STRING_H)); //交易日期 格式:YYYYMMDD bizContent.setTradeTime(DateUtil.getNow(DateUtil.DATE_FORMATE_STRING_N)); //交易时间hhmmss //bizContent.setAttach("1231"); //商户附加信息 bizContent.setOrderAmt(PayUtil.moneyToIntegerStr(payAmount)); //交易金额 //bizContent.setSubAppId("wxfb72f1a7d061d631"); //子商户应用号 ```