parent
ed90bb1f6c
commit
ae0a9b377f
@ -0,0 +1,35 @@
|
|||||||
|
package com.cyl.wechat;
|
||||||
|
|
||||||
|
import com.cyl.wechat.response.JssdkConfigResponse;
|
||||||
|
import org.springframework.http.ResponseEntity;
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/no-auth/wechat")
|
||||||
|
public class WechatController {
|
||||||
|
|
||||||
|
@GetMapping("/jssdk")
|
||||||
|
public ResponseEntity<JssdkConfigResponse> getJssdkConfig(){
|
||||||
|
String appId = WechatPayData.appId;
|
||||||
|
String nonceStr = WechatPayUtil.generateNonceStr();
|
||||||
|
long timeStamp = WechatPayUtil.getCurrentTimestamp();
|
||||||
|
String signature = Stream.of(appId, String.valueOf(timeStamp), nonceStr)
|
||||||
|
.collect(Collectors.joining("\n", "", "\n"));
|
||||||
|
JssdkConfigResponse response = new JssdkConfigResponse();
|
||||||
|
response.setAppId(appId);
|
||||||
|
List<String> jsApiList = new ArrayList<>();
|
||||||
|
jsApiList.add("chooseWXPay");
|
||||||
|
response.setJsApiList(jsApiList);
|
||||||
|
response.setNonceStr(nonceStr);
|
||||||
|
response.setTimeStamp(String.valueOf(timeStamp));
|
||||||
|
response.setSignature(signature);
|
||||||
|
return ResponseEntity.ok(response);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,20 @@
|
|||||||
|
package com.cyl.wechat.response;
|
||||||
|
|
||||||
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class JssdkConfigResponse {
|
||||||
|
@ApiModelProperty("appId")
|
||||||
|
private String appId;
|
||||||
|
@ApiModelProperty("timeStamp")
|
||||||
|
private String timeStamp;
|
||||||
|
@ApiModelProperty("nonceStr")
|
||||||
|
private String nonceStr;
|
||||||
|
@ApiModelProperty("signature")
|
||||||
|
private String signature;
|
||||||
|
@ApiModelProperty("jsApiList")
|
||||||
|
private List<String> jsApiList;
|
||||||
|
}
|
||||||
Loading…
Reference in new issue