content: /*
   ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
   ~                                                                               ~
   ~ The MIT License (MIT)                                                         ~
   ~                                                                               ~
   ~ Copyright (c) 2015-2025 miaixz.org and other contributors.                    ~
   ~                                                                               ~
   ~ Permission is hereby granted, free of charge, to any person obtaining a copy  ~
   ~ of this software and associated documentation files (the "Software"), to deal ~
   ~ in the Software without restriction, including without limitation the rights  ~
   ~ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell     ~
   ~ copies of the Software, and to permit persons to whom the Software is         ~
   ~ furnished to do so, subject to the following conditions:                      ~
   ~                                                                               ~
   ~ The above copyright notice and this permission notice shall be included in    ~
   ~ all copies or substantial portions of the Software.                           ~
   ~                                                                               ~
   ~ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR    ~
   ~ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,      ~
   ~ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE   ~
   ~ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER        ~
   ~ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, ~
   ~ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN     ~
   ~ THE SOFTWARE.                                                                 ~
   ~                                                                               ~
   ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
  */
  package org.miaixz.bus.notify.metric.jpush;
  
  import java.util.Base64;
  import java.util.HashMap;
  import java.util.Map;
  import java.util.Objects;
  
  import org.miaixz.bus.core.basic.entity.Message;
  import org.miaixz.bus.core.lang.Charset;
  import org.miaixz.bus.core.lang.MediaType;
  import org.miaixz.bus.core.lang.Symbol;
  import org.miaixz.bus.core.net.HTTP;
  import org.miaixz.bus.extra.json.JsonKit;
  import org.miaixz.bus.http.Httpx;
  import org.miaixz.bus.notify.Context;
  import org.miaixz.bus.notify.magic.ErrorCode;
  import org.miaixz.bus.notify.metric.AbstractProvider;
  
  /**
   * 极光短信
   *
   * @author Kimi Liu
   * @since Java 17+
   */
  public class JpushSmsProvider extends AbstractProvider<JpushMaterial, Context> {
  
      public JpushSmsProvider(Context context) {
          super(context);
      }
  
      @Override
      public Message send(JpushMaterial entity) {
          Map<String, String> bodys = new HashMap<>();
          bodys.put("sign_id", entity.getSignature());
          bodys.put("mobile", entity.getReceive());
          bodys.put("temp_id", entity.getTemplate());
          bodys.put("temp_para", entity.getParams());
  
          Map<String, String> headers = new HashMap<>();
          headers.put(HTTP.CONTENT_TYPE, MediaType.APPLICATION_JSON);
          headers.put(HTTP.AUTHORIZATION, "Basic " + getSign());
  
          String response = Httpx.post(this.getUrl(entity), bodys, headers);
          boolean succeed = Objects.equals(JsonKit.getValue(response, "success_count"), 0);
          String errcode = succeed ? ErrorCode._SUCCESS.getKey() : ErrorCode._FAILURE.getKey();
          String errmsg = succeed ? ErrorCode._SUCCESS.getValue() : ErrorCode._FAILURE.getValue();
  
          return Message.builder().errcode(errcode).errmsg(errmsg).build();
      }
  
      private String getSign() {
          String origin = context.getAppKey() + Symbol.COLON + context.getAppSecret();
          return Base64.getEncoder().encodeToString(origin.getBytes(Charset.UTF_8));
      }
  
  }
  