Selaa lähdekoodia

更新微信小程序相关配置文件和关于我们的配置程序

yanliming 1 kuukausi sitten
vanhempi
commit
bcb7192f21

+ 5 - 0
common/src/main/java/com/jpsoft/employment/modules/base/entity/AboutUs.java

@@ -74,4 +74,9 @@ public class AboutUs {
 
 	@ApiModelProperty(value = "标题说明")
 	private String title;
+
+	@ApiModelProperty(value = "内容类型")
+	private String contentType;
+
+
 		}

+ 8 - 1
common/src/main/resources/mapper/base/AboutUs.xml

@@ -22,6 +22,9 @@
 			<result property="content" column="content_" />
 			<result property="type" column="type_" />
 			<result property="title" column="title_" />
+			<result property="contentType" column="content_type" />
+
+
 			</resultMap>
 	<insert id="insert" parameterType="com.jpsoft.employment.modules.base.entity.AboutUs">
 	<!--
@@ -32,7 +35,7 @@
 	<![CDATA[
 		insert into base_about_us
 	    (id_,user_agreement,privacy_policy,disclaimer,create_time,update_time,del_flag,create_by,update_by
-	    ,receiving_account,bank_,account_number,payment_code,phone_,code_,content_,type_,title_)
+	    ,receiving_account,bank_,account_number,payment_code,phone_,code_,content_,type_,title_,content_type)
 		values
 		(
 #{id,jdbcType=VARCHAR}
@@ -53,6 +56,7 @@
 ,#{content,jdbcType=VARCHAR}
 ,#{type,jdbcType=VARCHAR}
 ,#{title,jdbcType=VARCHAR}
+,#{contentType,jdbcType=VARCHAR}
 		)
 	]]>
 	</insert>
@@ -113,6 +117,9 @@
 			<if test="title!=null">
 				title_=#{title,jdbcType=VARCHAR},
 			</if>
+			<if test="contentType!=null">
+				content_type=#{contentType,jdbcType=VARCHAR},
+			</if>
 		</set>
 	where id_=#{id}
 	</update>

+ 21 - 0
web/src/main/java/com/jpsoft/employment/modules/pay/properties/WxCustom.java

@@ -0,0 +1,21 @@
+package com.jpsoft.employment.modules.pay.properties;
+
+
+import lombok.Data;
+import org.springframework.boot.context.properties.ConfigurationProperties;
+import org.springframework.stereotype.Component;
+
+@Data
+@ConfigurationProperties(prefix = "wx.custom")
+@Component
+public class WxCustom {
+    /**
+     * 设置微信公众号或者小程序等的appid
+     */
+    private String appId;
+
+    /**
+     * 设置微信公众号或者小程序等的appSecret
+     */
+    private String appSecret;
+}

+ 21 - 0
web/src/main/java/com/jpsoft/employment/modules/pay/properties/WxMini.java

@@ -0,0 +1,21 @@
+package com.jpsoft.employment.modules.pay.properties;
+
+import lombok.Data;
+import org.springframework.boot.context.properties.ConfigurationProperties;
+import org.springframework.stereotype.Component;
+
+@Data
+@ConfigurationProperties(prefix = "wx.mini")
+@Component
+public class WxMini {
+    /**
+     * 设置微信公众号或者小程序等的appid
+     */
+    private String appId;
+
+    /**
+     * 设置微信公众号或者小程序等的appSecret
+     */
+    private String appSecret;
+    private String token;
+}

+ 87 - 0
web/src/main/java/com/jpsoft/employment/modules/wechat/controller/WxCustomController.java

@@ -0,0 +1,87 @@
+package com.jpsoft.employment.modules.wechat.controller;
+
+import com.jpsoft.employment.modules.common.dto.MessageResult;
+import com.jpsoft.employment.modules.common.utils.WeixinUtil;
+import com.jpsoft.employment.modules.pay.properties.WxCustom;
+import com.jpsoft.employment.modules.pay.properties.WxMini;
+import com.jpsoft.employment.modules.wechat.entity.AccessToken;
+import com.jpsoft.employment.modules.wechat.entity.SessionKey;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.StringUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.data.redis.core.ValueOperations;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.RequestMapping;
+
+import java.util.HashMap;
+import java.util.concurrent.TimeUnit;
+
+@Slf4j
+@RequestMapping("/wechatCustom")
+@Api(description = "小程序")
+public class WxCustomController {
+    @Autowired
+    private WxCustom wxCustom;
+
+    @Autowired
+    private ValueOperations<String, Object> valueOperations;
+
+
+    @ApiOperation(value = "获取公众号用户信息")
+    @GetMapping(value = "findAppletUserInfoz/{code}")
+    public MessageResult findAppletUserInfo(@PathVariable String code) {
+        try {
+            log.warn("code=" + code);
+            log.warn("appId=" + wxCustom.getAppId());
+            log.warn("appSecret=" + wxCustom.getAppSecret());
+
+            SessionKey sessionKey = WeixinUtil.getSessionKey(wxCustom.getAppId(), wxCustom.getAppSecret(), code);
+
+
+            if (sessionKey != null && StringUtils.isNotBlank(sessionKey.getOpenid())) {
+                String openId = sessionKey.getOpenid();
+                System.out.println("openId:" + openId);
+                HashMap<String, Object> dataMap = new HashMap<String, Object>();
+                dataMap.put("openId", openId);
+
+//                UserInfo userInfo = WeixinUtil.getUserInfo(openId, sessionKey.getSessionKey());
+//
+//                HashMap<String, Object> dataMap = new HashMap<String, Object>();
+//
+//                dataMap.put("userInfo", userInfo);
+
+                return new MessageResult(true, "获取信息成功", openId, 200);
+
+            } else {
+                return new MessageResult(false, "获取信息失败", "", 400);
+            }
+
+        } catch (Exception ex) {
+            ex.printStackTrace();
+            return new MessageResult(false, "系统错误", "", 500);
+        }
+    }
+
+    @ApiOperation(value = "获取小程序用户手机号信息")
+    @GetMapping(value = "findUserPhoneNumber/{code}")
+    public MessageResult findUserPhoneNumber(@PathVariable String code) {
+        try {
+
+            String accessToken = (String)valueOperations.get("accessToken");
+            if(StringUtils.isEmpty(accessToken)){
+                AccessToken token = WeixinUtil.getAccessToken(wxCustom.getAppId(), wxCustom.getAppSecret());
+                accessToken = token.getToken();
+                valueOperations.set("accessToken",token.getToken(),2, TimeUnit.HOURS);
+            }
+            String phone = WeixinUtil.getUserPhoneNumber(accessToken,code);
+
+            return new MessageResult(true, "成功", phone, 200);
+        } catch (Exception ex) {
+            ex.printStackTrace();
+            return new MessageResult(false, "系统错误", "", 500);
+        }
+    }
+}

+ 87 - 0
web/src/main/java/com/jpsoft/employment/modules/wechat/controller/WxMiniController.java

@@ -0,0 +1,87 @@
+package com.jpsoft.employment.modules.wechat.controller;
+
+import com.jpsoft.employment.modules.common.dto.MessageResult;
+import com.jpsoft.employment.modules.common.utils.WeixinUtil;
+import com.jpsoft.employment.modules.pay.properties.WxMini;
+import com.jpsoft.employment.modules.wechat.entity.AccessToken;
+import com.jpsoft.employment.modules.wechat.entity.SessionKey;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.StringUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.data.redis.core.ValueOperations;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.RequestMapping;
+
+import java.util.HashMap;
+import java.util.concurrent.TimeUnit;
+
+@Slf4j
+@RequestMapping("/wechatMini")
+@Api(description = "小程序")
+public class WxMiniController {
+
+    @Autowired
+    private WxMini wxMini;
+
+    @Autowired
+    private ValueOperations<String, Object> valueOperations;
+
+
+    @ApiOperation(value = "获取公众号用户信息")
+    @GetMapping(value = "findAppletUserInfoz/{code}")
+    public MessageResult findAppletUserInfo(@PathVariable String code) {
+        try {
+            log.warn("code=" + code);
+            log.warn("appId=" + wxMini.getAppId());
+            log.warn("appSecret=" + wxMini.getAppSecret());
+
+            SessionKey sessionKey = WeixinUtil.getSessionKey(wxMini.getAppId(), wxMini.getAppSecret(), code);
+
+
+            if (sessionKey != null && StringUtils.isNotBlank(sessionKey.getOpenid())) {
+                String openId = sessionKey.getOpenid();
+                System.out.println("openId:" + openId);
+                HashMap<String, Object> dataMap = new HashMap<String, Object>();
+                dataMap.put("openId", openId);
+
+//                UserInfo userInfo = WeixinUtil.getUserInfo(openId, sessionKey.getSessionKey());
+//
+//                HashMap<String, Object> dataMap = new HashMap<String, Object>();
+//
+//                dataMap.put("userInfo", userInfo);
+
+                return new MessageResult(true, "获取信息成功", openId, 200);
+
+            } else {
+                return new MessageResult(false, "获取信息失败", "", 400);
+            }
+
+        } catch (Exception ex) {
+            ex.printStackTrace();
+            return new MessageResult(false, "系统错误", "", 500);
+        }
+    }
+
+    @ApiOperation(value = "获取小程序用户手机号信息")
+    @GetMapping(value = "findUserPhoneNumber/{code}")
+    public MessageResult findUserPhoneNumber(@PathVariable String code) {
+        try {
+
+            String accessToken = (String)valueOperations.get("accessToken");
+            if(StringUtils.isEmpty(accessToken)){
+                AccessToken token = WeixinUtil.getAccessToken(wxMini.getAppId(), wxMini.getAppSecret());
+                accessToken = token.getToken();
+                valueOperations.set("accessToken",token.getToken(),2, TimeUnit.HOURS);
+            }
+            String phone = WeixinUtil.getUserPhoneNumber(accessToken,code);
+
+            return new MessageResult(true, "成功", phone, 200);
+        } catch (Exception ex) {
+            ex.printStackTrace();
+            return new MessageResult(false, "系统错误", "", 500);
+        }
+    }
+}

+ 9 - 7
web/src/main/resources/application.yml

@@ -116,13 +116,15 @@ pagehelper:
 
 
 wx:
-  #错误
-  appId: wx014362202dd87dd7
-  appSecret: aaf8db83ff69c3716a62e3d5bd21c292
-applet:
-  #三得利小程序
-  appId: wx7eec18cd89b9d777
-  appSecret: 5a0aa258fda3e75097a80764dab73202
+  #客户端
+  custom:
+    appId: wx81663812d6911100
+    appSecret: 873e039353fed747b0dd052ab10f179e
+  mini:
+    #师傅端
+    appId: wxa7c3f0f8b4758e1f
+    appSecret: 2115914d99fe6fbf2d0798d7dad71cb9
+    token: weixin
 
 #oss:
 #  accessKeyId: LTAILGOo7bwpkvnq