@@ -2,9 +2,7 @@ package me.chanjar.weixin.mp.api; | |||||
import me.chanjar.weixin.common.bean.WxCardApiSignature; | import me.chanjar.weixin.common.bean.WxCardApiSignature; | ||||
import me.chanjar.weixin.common.error.WxErrorException; | import me.chanjar.weixin.common.error.WxErrorException; | ||||
import me.chanjar.weixin.mp.bean.card.WxMpCardLandingPageCreateRequest; | |||||
import me.chanjar.weixin.mp.bean.card.WxMpCardLandingPageCreateResult; | |||||
import me.chanjar.weixin.mp.bean.card.WxMpCardQrcodeCreateResult; | |||||
import me.chanjar.weixin.mp.bean.card.*; | |||||
import me.chanjar.weixin.mp.bean.result.WxMpCardResult; | import me.chanjar.weixin.mp.bean.result.WxMpCardResult; | ||||
/** | /** | ||||
@@ -14,6 +12,7 @@ import me.chanjar.weixin.mp.bean.result.WxMpCardResult; | |||||
* @author yuanqixun 2018-08-29 | * @author yuanqixun 2018-08-29 | ||||
*/ | */ | ||||
public interface WxMpCardService { | public interface WxMpCardService { | ||||
String CARD_CREATE = "https://api.weixin.qq.com/card/create"; | |||||
String CARD_GET = "https://api.weixin.qq.com/card/get"; | String CARD_GET = "https://api.weixin.qq.com/card/get"; | ||||
String CARD_GET_TICKET = "https://api.weixin.qq.com/cgi-bin/ticket/getticket?type=wx_card"; | String CARD_GET_TICKET = "https://api.weixin.qq.com/cgi-bin/ticket/getticket?type=wx_card"; | ||||
String CARD_CODE_DECRYPT = "https://api.weixin.qq.com/card/code/decrypt"; | String CARD_CODE_DECRYPT = "https://api.weixin.qq.com/card/code/decrypt"; | ||||
@@ -142,6 +141,14 @@ public interface WxMpCardService { | |||||
*/ | */ | ||||
String addTestWhiteList(String openid) throws WxErrorException; | String addTestWhiteList(String openid) throws WxErrorException; | ||||
/** | |||||
* | |||||
* @param cardCreateMessage | |||||
* @return | |||||
* @throws WxErrorException | |||||
*/ | |||||
WxMpCardCreateResult createCard(WxMpCardCreateMessage cardCreateMessage) throws WxErrorException; | |||||
/** | /** | ||||
* 创建卡券二维码 | * 创建卡券二维码 | ||||
* | * | ||||
@@ -3,6 +3,7 @@ package me.chanjar.weixin.mp.api.impl; | |||||
import java.util.Arrays; | import java.util.Arrays; | ||||
import java.util.concurrent.locks.Lock; | import java.util.concurrent.locks.Lock; | ||||
import me.chanjar.weixin.mp.bean.card.*; | |||||
import org.apache.commons.lang3.StringUtils; | import org.apache.commons.lang3.StringUtils; | ||||
import org.slf4j.Logger; | import org.slf4j.Logger; | ||||
import org.slf4j.LoggerFactory; | import org.slf4j.LoggerFactory; | ||||
@@ -22,9 +23,6 @@ import me.chanjar.weixin.common.util.crypto.SHA1; | |||||
import me.chanjar.weixin.common.util.http.SimpleGetRequestExecutor; | import me.chanjar.weixin.common.util.http.SimpleGetRequestExecutor; | ||||
import me.chanjar.weixin.mp.api.WxMpCardService; | import me.chanjar.weixin.mp.api.WxMpCardService; | ||||
import me.chanjar.weixin.mp.api.WxMpService; | import me.chanjar.weixin.mp.api.WxMpService; | ||||
import me.chanjar.weixin.mp.bean.card.WxMpCardLandingPageCreateRequest; | |||||
import me.chanjar.weixin.mp.bean.card.WxMpCardLandingPageCreateResult; | |||||
import me.chanjar.weixin.mp.bean.card.WxMpCardQrcodeCreateResult; | |||||
import me.chanjar.weixin.mp.bean.result.WxMpCardResult; | import me.chanjar.weixin.mp.bean.result.WxMpCardResult; | ||||
import me.chanjar.weixin.mp.enums.TicketType; | import me.chanjar.weixin.mp.enums.TicketType; | ||||
import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder; | import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder; | ||||
@@ -265,6 +263,13 @@ public class WxMpCardServiceImpl implements WxMpCardService { | |||||
return respone; | return respone; | ||||
} | } | ||||
@Override | |||||
public WxMpCardCreateResult createCard(WxMpCardCreateMessage cardCreateMessage) throws WxErrorException { | |||||
String response = this.wxMpService.post(CARD_CREATE, GSON.toJson(cardCreateMessage)); | |||||
return WxMpCardCreateResult.fromJson(response); | |||||
} | |||||
/** | /** | ||||
* 创建卡券二维码. | * 创建卡券二维码. | ||||
*/ | */ | ||||
@@ -0,0 +1,31 @@ | |||||
package me.chanjar.weixin.mp.bean.card; | |||||
import com.google.gson.annotations.SerializedName; | |||||
import lombok.Data; | |||||
import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder; | |||||
import java.io.Serializable; | |||||
/** | |||||
* . | |||||
* @author leeis | |||||
* @Date 2018/12/29 | |||||
*/ | |||||
@Data | |||||
public class Card implements Serializable { | |||||
private static final long serialVersionUID = -3697110761983756780L; | |||||
/** | |||||
* 基本信息. | |||||
*/ | |||||
@SerializedName("base_info") | |||||
private BaseInfo baseInfo; | |||||
/** | |||||
* 创建优惠券特有的高级字段. | |||||
*/ | |||||
@SerializedName("advanced_info") | |||||
private AdvancedInfo advancedInfo; | |||||
} |
@@ -0,0 +1,13 @@ | |||||
package me.chanjar.weixin.mp.bean.card; | |||||
import lombok.Data; | |||||
import java.io.Serializable; | |||||
/** | |||||
* @Author leeis | |||||
* @Date 2018/12/29 | |||||
*/ | |||||
@Data | |||||
public class CardCreateRequest implements Serializable { | |||||
} |
@@ -0,0 +1,39 @@ | |||||
package me.chanjar.weixin.mp.bean.card; | |||||
import com.google.gson.annotations.SerializedName; | |||||
import lombok.Data; | |||||
import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder; | |||||
import java.io.Serializable; | |||||
/** | |||||
* . | |||||
* @author leeis | |||||
* @Date 2018/12/29 | |||||
*/ | |||||
@Data | |||||
public final class CashCard extends Card implements Serializable { | |||||
private static final long serialVersionUID = 6965491956462769745L; | |||||
/** | |||||
* 代金券专用,表示起用金额(单位为分),如果无起用门槛则填0 | |||||
*/ | |||||
@SerializedName("least_cost") | |||||
private int leastCost; | |||||
/** | |||||
* 代金券专用,表示减免金额。(单位为分) | |||||
*/ | |||||
@SerializedName("reduce_cost") | |||||
private int reduceCost; | |||||
@Override | |||||
public String toString() { | |||||
return WxMpGsonBuilder.create().toJson(this); | |||||
} | |||||
public static CashCard fromJson(String json) { | |||||
return WxMpGsonBuilder.create().fromJson(json, CashCard.class); | |||||
} | |||||
} |
@@ -0,0 +1,25 @@ | |||||
package me.chanjar.weixin.mp.bean.card; | |||||
import com.google.gson.annotations.SerializedName; | |||||
import lombok.Data; | |||||
import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder; | |||||
import java.io.Serializable; | |||||
/** | |||||
* . | |||||
* @author leeis | |||||
* @Date 2018/12/29 | |||||
*/ | |||||
@Data | |||||
public class CashCardCreateRequest extends CardCreateRequest implements Serializable { | |||||
@SerializedName("card_type") | |||||
private String cardType = "CASH"; | |||||
private CashCard cash; | |||||
@Override | |||||
public String toString() { | |||||
return WxMpGsonBuilder.create().toJson(this); | |||||
} | |||||
} |
@@ -0,0 +1,32 @@ | |||||
package me.chanjar.weixin.mp.bean.card; | |||||
import com.google.gson.annotations.SerializedName; | |||||
import lombok.Data; | |||||
import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder; | |||||
import java.io.Serializable; | |||||
/** | |||||
* . | |||||
* @author leeis | |||||
* @Date 2018/12/29 | |||||
*/ | |||||
@Data | |||||
public final class DiscountCard extends Card implements Serializable { | |||||
private static final long serialVersionUID = 1704610082472315077L; | |||||
/** | |||||
* 折扣券专用,表示打折额度(百分比)。填30就是七折。 | |||||
*/ | |||||
private int discount; | |||||
@Override | |||||
public String toString() { | |||||
return WxMpGsonBuilder.create().toJson(this); | |||||
} | |||||
public static DiscountCard fromJson(String json) { | |||||
return WxMpGsonBuilder.create().fromJson(json, DiscountCard.class); | |||||
} | |||||
} |
@@ -0,0 +1,25 @@ | |||||
package me.chanjar.weixin.mp.bean.card; | |||||
import com.google.gson.annotations.SerializedName; | |||||
import lombok.Data; | |||||
import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder; | |||||
import java.io.Serializable; | |||||
/** | |||||
* . | |||||
* @author leeis | |||||
* @Date 2018/12/29 | |||||
*/ | |||||
@Data | |||||
public class DiscountCardCreateRequest extends CardCreateRequest implements Serializable { | |||||
@SerializedName("card_type") | |||||
private String cardType = "DISCOUNT"; | |||||
private DiscountCard discount; | |||||
@Override | |||||
public String toString() { | |||||
return WxMpGsonBuilder.create().toJson(this); | |||||
} | |||||
} |
@@ -0,0 +1,33 @@ | |||||
package me.chanjar.weixin.mp.bean.card; | |||||
import com.google.gson.annotations.SerializedName; | |||||
import lombok.Data; | |||||
import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder; | |||||
import java.io.Serializable; | |||||
/** | |||||
* . | |||||
* @author leeis | |||||
* @Date 2018/12/29 | |||||
*/ | |||||
@Data | |||||
public final class GeneralCard extends Card implements Serializable { | |||||
private static final long serialVersionUID = -1577656733441132585L; | |||||
/** | |||||
* 兑换券专用,填写兑换内容的名称。 | |||||
*/ | |||||
@SerializedName("default_detail") | |||||
private String defaultDetail; | |||||
@Override | |||||
public String toString() { | |||||
return WxMpGsonBuilder.create().toJson(this); | |||||
} | |||||
public static GeneralCard fromJson(String json) { | |||||
return WxMpGsonBuilder.create().fromJson(json, GeneralCard.class); | |||||
} | |||||
} |
@@ -0,0 +1,26 @@ | |||||
package me.chanjar.weixin.mp.bean.card; | |||||
import com.google.gson.annotations.SerializedName; | |||||
import lombok.Data; | |||||
import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder; | |||||
import java.io.Serializable; | |||||
/** | |||||
* . | |||||
* @author leeis | |||||
* @Date 2018/12/29 | |||||
*/ | |||||
@Data | |||||
public class GeneralCardCreateRequest extends CardCreateRequest implements Serializable { | |||||
@SerializedName("card_type") | |||||
private String cardType = "GENERAL_COUPON"; | |||||
@SerializedName("general_coupon") | |||||
private GeneralCard generalCoupon; | |||||
@Override | |||||
public String toString() { | |||||
return WxMpGsonBuilder.create().toJson(this); | |||||
} | |||||
} |
@@ -0,0 +1,32 @@ | |||||
package me.chanjar.weixin.mp.bean.card; | |||||
import com.google.gson.annotations.SerializedName; | |||||
import lombok.Data; | |||||
import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder; | |||||
import java.io.Serializable; | |||||
/** | |||||
* . | |||||
* @author leeis | |||||
* @Date 2018/12/29 | |||||
*/ | |||||
@Data | |||||
public final class GiftCard extends Card implements Serializable { | |||||
private static final long serialVersionUID = -6168739707511792266L; | |||||
/** | |||||
* 兑换券专用,填写兑换内容的名称。 | |||||
*/ | |||||
private String gift; | |||||
@Override | |||||
public String toString() { | |||||
return WxMpGsonBuilder.create().toJson(this); | |||||
} | |||||
public static GiftCard fromJson(String json) { | |||||
return WxMpGsonBuilder.create().fromJson(json, GiftCard.class); | |||||
} | |||||
} |
@@ -0,0 +1,25 @@ | |||||
package me.chanjar.weixin.mp.bean.card; | |||||
import com.google.gson.annotations.SerializedName; | |||||
import lombok.Data; | |||||
import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder; | |||||
import java.io.Serializable; | |||||
/** | |||||
* . | |||||
* @author leeis | |||||
* @Date 2018/12/29 | |||||
*/ | |||||
@Data | |||||
public class GiftCardCreateRequest extends CardCreateRequest implements Serializable { | |||||
@SerializedName("card_type") | |||||
private String cardType = "GIFT"; | |||||
private GiftCard gift; | |||||
@Override | |||||
public String toString() { | |||||
return WxMpGsonBuilder.create().toJson(this); | |||||
} | |||||
} |
@@ -0,0 +1,33 @@ | |||||
package me.chanjar.weixin.mp.bean.card; | |||||
import com.google.gson.annotations.SerializedName; | |||||
import lombok.Data; | |||||
import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder; | |||||
import java.io.Serializable; | |||||
/** | |||||
* . | |||||
* @author leeis | |||||
* @Date 2018/12/29 | |||||
*/ | |||||
@Data | |||||
public final class GrouponCard extends Card implements Serializable { | |||||
private static final long serialVersionUID = 3221312561666697005L; | |||||
/** | |||||
* 团购券专用,团购详情 | |||||
*/ | |||||
@SerializedName("deal_detail") | |||||
private String dealDetail; | |||||
@Override | |||||
public String toString() { | |||||
return WxMpGsonBuilder.create().toJson(this); | |||||
} | |||||
public static GrouponCard fromJson(String json) { | |||||
return WxMpGsonBuilder.create().fromJson(json, GrouponCard.class); | |||||
} | |||||
} |
@@ -0,0 +1,25 @@ | |||||
package me.chanjar.weixin.mp.bean.card; | |||||
import com.google.gson.annotations.SerializedName; | |||||
import lombok.Data; | |||||
import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder; | |||||
import java.io.Serializable; | |||||
/** | |||||
* . | |||||
* @author leeis | |||||
* @Date 2018/12/29 | |||||
*/ | |||||
@Data | |||||
public class GrouponCardCreateRequest extends CardCreateRequest implements Serializable { | |||||
@SerializedName("card_type") | |||||
private String cardType = "GROUPON"; | |||||
private GrouponCard groupon; | |||||
@Override | |||||
public String toString() { | |||||
return WxMpGsonBuilder.create().toJson(this); | |||||
} | |||||
} |
@@ -0,0 +1,23 @@ | |||||
package me.chanjar.weixin.mp.bean.card; | |||||
import com.google.gson.annotations.SerializedName; | |||||
import lombok.Data; | |||||
import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder; | |||||
import java.io.Serializable; | |||||
@Data | |||||
public final class WxMpCardCreateMessage implements Serializable { | |||||
@SerializedName("card") | |||||
private CardCreateRequest cardCreateRequest; | |||||
@Override | |||||
public String toString() { | |||||
return WxMpGsonBuilder.create().toJson(this); | |||||
} | |||||
public static WxMpCardCreateMessage fromJson(String json) { | |||||
return WxMpGsonBuilder.create().fromJson(json, WxMpCardCreateMessage.class); | |||||
} | |||||
} |
@@ -2,8 +2,10 @@ package me.chanjar.weixin.mp.api.impl; | |||||
import com.google.inject.Inject; | import com.google.inject.Inject; | ||||
import me.chanjar.weixin.common.bean.WxCardApiSignature; | import me.chanjar.weixin.common.bean.WxCardApiSignature; | ||||
import me.chanjar.weixin.common.error.WxErrorException; | |||||
import me.chanjar.weixin.mp.api.WxMpService; | import me.chanjar.weixin.mp.api.WxMpService; | ||||
import me.chanjar.weixin.mp.api.test.ApiTestModule; | import me.chanjar.weixin.mp.api.test.ApiTestModule; | ||||
import me.chanjar.weixin.mp.bean.card.*; | |||||
import me.chanjar.weixin.mp.bean.result.WxMpCardResult; | import me.chanjar.weixin.mp.bean.result.WxMpCardResult; | ||||
import org.testng.annotations.*; | import org.testng.annotations.*; | ||||
@@ -100,4 +102,98 @@ public class WxMpCardServiceImplTest { | |||||
assertNotNull(result); | assertNotNull(result); | ||||
System.out.println(result); | System.out.println(result); | ||||
} | } | ||||
@Test | |||||
public void testCreateGrouponCard() throws WxErrorException { | |||||
BaseInfo base = new BaseInfo(); | |||||
base.setLogoUrl("http://mmbiz.qpic.cn/mmbiz/iaL1LJM1mF9aRKPZJkmG8xXhiaHqkKSVMMWeN3hLut7X7hicFNjakmxibMLGWpXrEXB33367o7zHN0CwngnQY7zb7g/0"); | |||||
base.setBrandName("测试优惠券"); | |||||
base.setCodeType("CODE_TYPE_QRCODE"); | |||||
base.setTitle("测试标题"); | |||||
base.setColor("Color010"); | |||||
base.setNotice("测试Notice"); | |||||
base.setServicePhone("020-88888888"); | |||||
base.setDescription("不可与其他优惠同享\\n如需团购券发票,请在消费时向商户提出\\n店内均可使用,仅限堂食"); | |||||
DateInfo info = new DateInfo(); | |||||
info.setType("DATE_TYPE_FIX_TERM"); | |||||
info.setFixedBeginTerm(0); | |||||
info.setFixedTerm(30); | |||||
base.setDateInfo(info); | |||||
Sku sku = new Sku(); | |||||
sku.setQuantity(100); | |||||
base.setSku(sku); | |||||
base.setGetLimit(1); | |||||
base.setCanShare(true); | |||||
base.setCanGiveFriend(true); | |||||
base.setUseAllLocations(true); | |||||
base.setCenterTitle("顶部居中按钮"); | |||||
base.setCenterSubTitle("按钮下方的wording"); | |||||
base.setCenterUrl("www.qq.com"); | |||||
base.setCustomUrl("http://www.qq.com"); | |||||
base.setCustomUrlName("立即使用"); | |||||
base.setCustomUrlSubTitle("副标题tip"); | |||||
base.setPromotionUrlName("更多优惠"); | |||||
base.setPromotionUrl("http://www.qq.com"); | |||||
base.setLocationIdList("1234"); | |||||
//团购券 | |||||
WxMpCardCreateMessage grouponMessage = new WxMpCardCreateMessage(); | |||||
GrouponCardCreateRequest grouponCardCreateRequest = new GrouponCardCreateRequest(); | |||||
GrouponCard grouponCard = new GrouponCard(); | |||||
grouponCard.setBaseInfo(base); | |||||
grouponCard.setDealDetail("deal detail"); | |||||
grouponCardCreateRequest.setGroupon(grouponCard); | |||||
grouponMessage.setCardCreateRequest(grouponCardCreateRequest); | |||||
System.out.println(this.wxService.getCardService().createCard(grouponMessage)); | |||||
//现金券 | |||||
WxMpCardCreateMessage cashMessage = new WxMpCardCreateMessage(); | |||||
CashCardCreateRequest cashCardCreateRequest = new CashCardCreateRequest(); | |||||
CashCard cashCard = new CashCard(); | |||||
cashCard.setBaseInfo(base); | |||||
cashCard.setLeastCost(1000); | |||||
cashCard.setReduceCost(100); | |||||
cashCardCreateRequest.setCash(cashCard); | |||||
cashMessage.setCardCreateRequest(cashCardCreateRequest); | |||||
System.out.println(this.wxService.getCardService().createCard(cashMessage)); | |||||
//折扣券 | |||||
WxMpCardCreateMessage discountMessage = new WxMpCardCreateMessage(); | |||||
DiscountCardCreateRequest discountCardCreateRequest = new DiscountCardCreateRequest(); | |||||
DiscountCard discountCard = new DiscountCard(); | |||||
discountCard.setBaseInfo(base); | |||||
discountCard.setDiscount(30); | |||||
discountCardCreateRequest.setDiscount(discountCard); | |||||
discountMessage.setCardCreateRequest(discountCardCreateRequest); | |||||
System.out.println(this.wxService.getCardService().createCard(discountMessage)); | |||||
//兑换券 | |||||
WxMpCardCreateMessage giftMessage = new WxMpCardCreateMessage(); | |||||
GiftCardCreateRequest giftCardCreateRequest = new GiftCardCreateRequest(); | |||||
GiftCard giftCard = new GiftCard(); | |||||
giftCard.setBaseInfo(base); | |||||
giftCard.setGift("星巴克雪瑞纳咖啡大杯"); | |||||
giftCardCreateRequest.setGift(giftCard); | |||||
giftMessage.setCardCreateRequest(giftCardCreateRequest); | |||||
System.out.println(this.wxService.getCardService().createCard(giftMessage)); | |||||
//普通兑换券 | |||||
WxMpCardCreateMessage generalMessage = new WxMpCardCreateMessage(); | |||||
GeneralCardCreateRequest generalCardCreateRequest = new GeneralCardCreateRequest(); | |||||
GeneralCard generalCard = new GeneralCard(); | |||||
generalCard.setBaseInfo(base); | |||||
generalCard.setDefaultDetail("音乐木盒"); | |||||
generalCardCreateRequest.setGeneralCoupon(generalCard); | |||||
generalMessage.setCardCreateRequest(generalCardCreateRequest); | |||||
System.out.println(this.wxService.getCardService().createCard(generalMessage)); | |||||
} | |||||
} | } |
@@ -4,6 +4,7 @@ import cn.binarywang.wx.miniapp.bean.WxMaJscode2SessionResult; | |||||
import me.chanjar.weixin.common.error.WxErrorException; | import me.chanjar.weixin.common.error.WxErrorException; | ||||
import me.chanjar.weixin.mp.api.WxMpService; | import me.chanjar.weixin.mp.api.WxMpService; | ||||
import me.chanjar.weixin.mp.bean.result.WxMpOAuth2AccessToken; | import me.chanjar.weixin.mp.bean.result.WxMpOAuth2AccessToken; | ||||
import me.chanjar.weixin.open.bean.WxOpenCreateResult; | |||||
import me.chanjar.weixin.open.bean.WxOpenMaCodeTemplate; | import me.chanjar.weixin.open.bean.WxOpenMaCodeTemplate; | ||||
import me.chanjar.weixin.open.bean.message.WxOpenXmlMessage; | import me.chanjar.weixin.open.bean.message.WxOpenXmlMessage; | ||||
import me.chanjar.weixin.open.bean.result.WxOpenAuthorizerInfoResult; | import me.chanjar.weixin.open.bean.result.WxOpenAuthorizerInfoResult; | ||||
@@ -42,6 +43,8 @@ public interface WxOpenComponentService { | |||||
String MINIAPP_JSCODE_2_SESSION = "https://api.weixin.qq.com/sns/component/jscode2session?appid=%s&js_code=%s&grant_type=authorization_code&component_appid=%s"; | String MINIAPP_JSCODE_2_SESSION = "https://api.weixin.qq.com/sns/component/jscode2session?appid=%s&js_code=%s&grant_type=authorization_code&component_appid=%s"; | ||||
String CREATE_OPEN_URL= "https://api.weixin.qq.com/cgi-bin/open/create"; | |||||
WxMpService getWxMpServiceByAppid(String appid); | WxMpService getWxMpServiceByAppid(String appid); | ||||
/** | /** | ||||
@@ -168,4 +171,15 @@ public interface WxOpenComponentService { | |||||
* @see #getTemplateList | * @see #getTemplateList | ||||
*/ | */ | ||||
void deleteTemplate(long templateId) throws WxErrorException; | void deleteTemplate(long templateId) throws WxErrorException; | ||||
/** | |||||
* https://open.weixin.qq.com/cgi-bin/showdocument?action=dir_list&t=resource/res_list&verify=1&id=open1498704199_1bcax&token=6df5e3650041eff2cd3ec3662425ad8d7beec8d9&lang=zh_CN | |||||
* 创建 开放平台帐号并绑定公众号/小程序 | |||||
* | |||||
* https://api.weixin.qq.com/cgi-bin/open/create | |||||
* | |||||
* @param appId 公众号/小程序的appId | |||||
* @return | |||||
*/ | |||||
WxOpenCreateResult createOpenAccount(String appId) throws WxErrorException; | |||||
} | } |
@@ -17,6 +17,7 @@ import me.chanjar.weixin.open.api.WxOpenMaService; | |||||
import me.chanjar.weixin.open.api.WxOpenService; | import me.chanjar.weixin.open.api.WxOpenService; | ||||
import me.chanjar.weixin.open.bean.WxOpenAuthorizerAccessToken; | import me.chanjar.weixin.open.bean.WxOpenAuthorizerAccessToken; | ||||
import me.chanjar.weixin.open.bean.WxOpenComponentAccessToken; | import me.chanjar.weixin.open.bean.WxOpenComponentAccessToken; | ||||
import me.chanjar.weixin.open.bean.WxOpenCreateResult; | |||||
import me.chanjar.weixin.open.bean.WxOpenMaCodeTemplate; | import me.chanjar.weixin.open.bean.WxOpenMaCodeTemplate; | ||||
import me.chanjar.weixin.open.bean.auth.WxOpenAuthorizationInfo; | import me.chanjar.weixin.open.bean.auth.WxOpenAuthorizationInfo; | ||||
import me.chanjar.weixin.open.bean.message.WxOpenXmlMessage; | import me.chanjar.weixin.open.bean.message.WxOpenXmlMessage; | ||||
@@ -387,4 +388,14 @@ public class WxOpenComponentServiceImpl implements WxOpenComponentService { | |||||
param.addProperty("template_id", templateId); | param.addProperty("template_id", templateId); | ||||
post(DELETE_TEMPLATE_URL, param.toString(), "access_token"); | post(DELETE_TEMPLATE_URL, param.toString(), "access_token"); | ||||
} | } | ||||
@Override | |||||
public WxOpenCreateResult createOpenAccount(String appId) throws WxErrorException { | |||||
JsonObject param = new JsonObject(); | |||||
param.addProperty("appid", appId); | |||||
String json = post(CREATE_OPEN_URL, param.toString(), "access_token"); | |||||
return WxOpenCreateResult.fromJson(json); | |||||
} | |||||
} | } |
@@ -0,0 +1,36 @@ | |||||
package me.chanjar.weixin.open.bean; | |||||
import cn.binarywang.wx.miniapp.util.json.WxMaGsonBuilder; | |||||
import com.google.gson.annotations.SerializedName; | |||||
import lombok.Data; | |||||
import lombok.EqualsAndHashCode; | |||||
import me.chanjar.weixin.common.util.json.WxGsonBuilder; | |||||
import java.io.Serializable; | |||||
/** | |||||
* <pre> | |||||
* code换取session_key接口的响应 | |||||
* 文档地址:https://mp.weixin.qq.com/debug/wxadoc/dev/api/api-login.html#wxloginobject | |||||
* 微信返回报文:{"session_key":"nzoqhc3OnwHzeTxJs+inbQ==","openid":"oVBkZ0aYgDMDIywRdgPW8-joxXc4"} | |||||
* </pre> | |||||
* @author <a href="https://github.com/binarywang">Binary Wang</a> | |||||
*/ | |||||
@Data | |||||
@EqualsAndHashCode(callSuper = false) | |||||
public class WxOpenCreateResult implements Serializable { | |||||
@SerializedName("open_appid") | |||||
private String openAppid; | |||||
@SerializedName("errcode") | |||||
private String errcode; | |||||
@SerializedName("errmsg") | |||||
private String errmsg; | |||||
public static WxOpenCreateResult fromJson(String json) { | |||||
return WxGsonBuilder.create().fromJson(json, WxOpenCreateResult.class); | |||||
} | |||||
} |