在华为云号码隐私保护给的样例代码上进行二次封装
controller
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.oss.oss_demo.entity.*;
import com.oss.oss_demo.service.AXBInterface;
import com.oss.oss_demo.service.AXYBInterface;
import com.oss.oss_demo.service.impl.AXBInterfaceImpl;
import com.oss.oss_demo.service.impl.AXYBInterfaceImpl;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import java.sql.*;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
@RestController
@RequestMapping("/huaweicloud/secret")
@Api(tags = "华为云号码隐私保护")
public class HuaWeiSecretController {
private final static String OMPAPPKEY = ""; // APP_Key AXB
private final static String OMPAPPSECRET = ""; // APP_Secret AXB
private final static String OMPDOMAINNAME = "https://rtcapi.cn-north-1.myhuaweicloud.com:12543"; // APP接入地址
private String AXYBAPPKEY ="";// AXYB模式APP_Key
private String AXYBAPPSECRET =""; // AXYB模式APP_Secret
@RequestMapping(value = "axbBindNumber",method = RequestMethod.POST)
@ApiOperation("隐私号码AXB绑定")
@ApiImplicitParams({
@ApiImplicitParam(name = "relationNum",value = "X号码",dataType = "String",required = true),
@ApiImplicitParam(name = "callerNum",value ="A号码",dataType = "String",required =true ),
@ApiImplicitParam(name = "calleeNum",value ="B号码",dataType = "String",required =true ),
@ApiImplicitParam(name = "duration",value ="绑定关系保持时间,单位为秒",dataType = "Long",required =true ),
@ApiImplicitParam(name = "recordFlag",value = "是否需要针对该绑定关系产生的所有通话录音",dataType = "Boolean"),
@ApiImplicitParam(name = "recordHintTone",value = "该参数用于设置录音提示音",dataType = "String"),
@ApiImplicitParam(name = "callerHintTone",value = "设置A拨打X号码时的通话前等待音",dataType = "String"),
@ApiImplicitParam(name = "calleeHintTone",value = "设置B拨打X号码时的通话前等待音",dataType = "String"),
@ApiImplicitParam(name = "maxDuration",value = "设置允许单次通话进行的最长时间,单位为分钟",dataType = "Long",required = true),
@ApiImplicitParam(name = "lastMinVoice",value = "设置通话剩余最后一分钟时的提示音",dataType = "String"),
@ApiImplicitParam(name = "privateSms",value = "设置该绑定关系是否支持短信功能",dataType = "Boolean")
})
public String axbBindNumber( String relationNum, String callerNum, String calleeNum, Integer duration,
Boolean recordFlag, String recordHintTone, String callerHintTone, String calleeHintTone,
Integer maxDuration, String lastMinVoice, Boolean privateSms){
AXBInterface axb =new AXBInterfaceImpl(OMPAPPKEY, OMPAPPSECRET, OMPDOMAINNAME);
String result =axb.axbBindNumber(relationNum, callerNum, calleeNum, duration, recordFlag, recordHintTone, callerHintTone, calleeHintTone, maxDuration, lastMinVoice, privateSms);
return result;
}
@RequestMapping(value = "axbModifyNumber",method = RequestMethod.PUT)
@ApiOperation("修改已设置的AXB绑定关系的相关信息")
public String axbModifyNumber(String subscriptionId, String callerNum, String calleeNum,Integer duration,
Boolean recordFlag,String callerHintTone,String calleeHintTone,
Integer maxDuration,String lastMinVoice,Boolean privateSms){
AXBInterface axb =new AXBInterfaceImpl(OMPAPPKEY, OMPAPPSECRET, OMPDOMAINNAME);
String result =axb.axbModifyNumber(subscriptionId, callerNum, calleeNum, duration, recordFlag, callerHintTone, calleeHintTone, maxDuration, lastMinVoice, privateSms);
return result;
}
@RequestMapping(value = "axbUnbindNumber",method = RequestMethod.DELETE)
@ApiOperation("解除已设置的AXB绑定关系")
public String axbUnbindNumber(String subscriptionId, String relationNum){
AXBInterface axb =new AXBInterfaceImpl(OMPAPPKEY, OMPAPPSECRET, OMPDOMAINNAME);
String result =axb.axbUnbindNumber(subscriptionId, relationNum);
return result;
}
@RequestMapping(value = "axbQueryBindRelation",method = RequestMethod.GET)
@ApiOperation("查询已设置的AXB绑定关系的相关信息")
public String axbQueryBindRelation(String subscriptionId, String relationNum, Integer pageIndex,Integer pageSize){
AXBInterface axb =new AXBInterfaceImpl(OMPAPPKEY, OMPAPPSECRET, OMPDOMAINNAME);
String result =axb.axbQueryBindRelation(subscriptionId, relationNum, pageIndex, pageSize);
return result;
}
@RequestMapping(value = "axbGetRecordDownloadLink",method =RequestMethod.GET )
@ApiOperation("AXB模式获取录音文件的下载地址")
public String axbGetRecordDownloadLink(String recordDomain, String fileName){
AXBInterface axb =new AXBInterfaceImpl(OMPAPPKEY, OMPAPPSECRET, OMPDOMAINNAME);
String result =axb.axbGetRecordDownloadLink(recordDomain, fileName);
return result;
}
@RequestMapping(value ="axbStopCall",method = RequestMethod.POST)
@ApiOperation("AXB模式终止呼叫")
public String axbStopCall(String sessionid){
AXBInterface axb =new AXBInterfaceImpl(OMPAPPKEY, OMPAPPSECRET, OMPDOMAINNAME);
String result =axb.axbStopCall(sessionid);
return result;
}
@PostMapping(value ="axbCallEventInform")
@ApiOperation("AXB模式呼叫事件通知接口(华为云推送)")
public void axbCallEventInform(@RequestBody CallForm callForm) throws ClassNotFoundException, SQLException, ParseException {
System.out.println("============================");
System.out.println(callForm);
System.out.println("========== JSON ============");
System.out.println(JSON.toJSONString(callForm.toString()));
System.out.println("============================");
callFormList.add(callForm);
Class.forName(JDBC_DRIVER);
Connection conn = DriverManager.getConnection(DB_URL,USER,PASS);
String sql ="INSERT INTO HuaWeiCallEventInform (eventType,`timestamp`,sessionId,caller,called,subscriptionId,stateCode,stateDesc)" +
"values (?,?,?,?,?,?,?,?)";
PreparedStatement pst = conn.prepareStatement(sql);
if(callForm.getEventType() != null){
pst.setString(1,callForm.getEventType());
pst.setTimestamp(2, UTCtoCST(callForm.getStatusInfo().getTimestamp()));
pst.setString(3,callForm.getStatusInfo().getSessionId());
pst.setString(4,callForm.getStatusInfo().getCaller());
pst.setString(5,callForm.getStatusInfo().getCalled());
pst.setString(6,callForm.getStatusInfo().getSubscriptionId());
if(callForm.getStatusInfo().getStateCode() ==null){
pst.setInt(7,1);
}else{
pst.setInt(7,callForm.getStatusInfo().getStateCode());
}
pst.setString(8,callForm.getStatusInfo().getStateDesc());
pst.addBatch();
}
pst.executeBatch();
conn.close();
}
private List<FeeInfo> axbFeeFormList = new ArrayList<FeeInfo>();
@PostMapping(value = "axbCallInform")
@ApiOperation("AXB模式话单通知接口(华为云推送)")
public void axbCallInform(@RequestBody FeeForm form) throws ClassNotFoundException, SQLException, ParseException {
System.out.println("============================");
System.out.println(form.toString());
System.out.println("========== JSON ============");
System.out.println(JSON.toJSONString(form));
System.out.println("============================");
axbFeeFormList.addAll(form.getFeeLst());
Class.forName(JDBC_DRIVER);
Connection conn = DriverManager.getConnection(DB_URL,USER,PASS);
String sql ="INSERT INTO HuaWeiCallInform (Direction,Icid,BindNum,SessionId,CallerNum,CalleeNum,FwdDisplayNum,FwdDstNum,CallInTime,FwdStartTime,FwdAlertingTime,FwdAnswerTime," +
"CallEndTime,FwdUnaswRsn,FailTime,SipStatusCode,RecordFlag,RecordStartTime,RecordObjectName,RecordBucketName,RecordDomain,ServiceType,HostName,SubscriptionId)" +
"values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
PreparedStatement pst = conn.prepareStatement(sql);
for (FeeInfo f: form.getFeeLst()) {
if(f.getSessionId() != null){
pst.setInt(1,f.getDirection());
pst.setString(2,f.getIcid());
pst.setString(3,f.getBindNum());
pst.setString(4,f.getSessionId());
pst.setString(5,f.getCallerNum());
pst.setString(6,f.getCalleeNum());
pst.setString(7,f.getFwdDisplayNum());
pst.setString(8,f.getFwdDstNum());
pst.setTimestamp(9,UTCtoCST(f.getCallInTime()));
pst.setTimestamp(10,UTCtoCST(f.getFwdStartTime()));
pst.setTimestamp(11,UTCtoCST(f.getFwdAlertingTime()));
pst.setTimestamp(12,UTCtoCST(f.getFwdAnswerTime()));
pst.setTimestamp(13,UTCtoCST(f.getCallEndTime()));
pst.setInt(14,f.getFwdUnaswRsn());
pst.setString(15,f.getFailTime());
pst.setInt(16,f.getSipStatusCode());
pst.setInt(17,f.getRecordFlag());
pst.setTimestamp(18,UTCtoCST(f.getRecordStartTime()));
pst.setString(19,f.getRecordObjectName());
pst.setString(20,f.getRecordBucketName());
pst.setString(21,f.getRecordDomain());
pst.setString(22,f.getServiceType());
pst.setString(23,f.getHostName());
pst.setString(24,f.getSubscriptionId());
pst.addBatch();
}
}
pst.executeBatch();
conn.close();
}
@GetMapping(value ="getCallNum")
@ApiOperation("AXB模式获取被叫号码隐私号")
@ApiImplicitParams({
@ApiImplicitParam(name ="areaCode",value ="区号",required = true),
@ApiImplicitParam(name ="callerNum",value = "主叫号码,如+8613012345678",required = true),
@ApiImplicitParam(name = "calleeNum",value = "被叫号码,如+8613112345678",required = true)
})
public String getCallNum(String areaCode,String callerNum,String calleeNum){
String axbBindNumberResult =axbBindNumber(areaCode,callerNum,calleeNum,7200,null,null,null,null,1440,null,null);
JSONObject object =JSONObject.parseObject(axbBindNumberResult);
String result =object.getString("relationNum");
return result;
}
/**
* 设置用户A和隐私号码X,AX、用户B和隐私号码Y的绑定关系
* @param origNum 申请开通AXYB业务的用户号码,填写为全局号码格式(包含国家码),如:+8613800000001或+8675528000002
* @param areaCode 区号,标示隐私号码归属的区域,申请AX绑定关系时,必须携带此参数;申请YB绑定关系时,该参数可选
* @param subscriptionId 填写为调用“AXYB模式绑定接口”接口时返回的绑定ID
* @param duration 绑定关系保持时间,单位为秒,取值范围0~7776000(90天
* @param recordHintTone 此字段用于设置使用录音功能的提示音,该参数在recordFlag为true时才有效,该参数仅在设置AX绑定时有效
* @param preVoiceX 设置对X号码播放的个性化通话前等待音,系统边给X号码绑定用户放音(只放一次音)边拨打Y号码绑定用户,该参数仅在设置AX绑定时有效
* @param preVoiceY 设置对Y号码播放的个性化通话前等待音,系统边给Y号码绑定用户放音(只放一次音)边拨打X号码绑定用户,该参数仅在设置YB绑定时有效
* @return
*/
@RequestMapping(value ="xyBindNumber",method = RequestMethod.POST)
@ApiOperation("设置用户A和隐私号码X,AX、用户B和隐私号码Y的绑定关系")
@ApiImplicitParams({
@ApiImplicitParam(name = "origNum",value = "申请开通AXYB业务的用户号码。填写为全局号码格式(包含国家码),如:+8613800000001",
dataType = "String",required = true),
@ApiImplicitParam(name = "areaCode",value = "区号,标示隐私号码归属的区域,申请AX绑定关系时,必须携带此参数;申请YB绑定关系时,该参数可选",
dataType = "String"),
@ApiImplicitParam(name = "subscriptionId",value = "“AXYB模式绑定接口”接口时返回的绑定ID,携带此参数,表示用户要申请的是YB绑定关系,否则表示用户要申请AX绑定关系",
dataType = "String"),
@ApiImplicitParam(name =