用友认证和付款接口调试

This commit is contained in:
yuxueliang0813 2024-09-09 16:26:54 +08:00
parent 27e4729ff8
commit 35037a686c
3 changed files with 61 additions and 50 deletions

View File

@ -15,8 +15,8 @@ import kd.bos.logging.LogFactory;
import kd.bos.orm.query.QFilter;
import kd.bos.servicehelper.BusinessDataServiceHelper;
import kd.sdk.plugin.Plugin;
import nccloud.open.api.auto.token.cur.utils.APICurUtils;
import okhttp3.*;
//import okio.ByteString;
import shkd.utils.DobeDWUtils;
import java.math.BigDecimal;
@ -28,22 +28,8 @@ import java.math.BigDecimal;
public class YongyouBIPOperation extends AbstractOperationServicePlugIn implements Plugin {
private static final Log log = LogFactory.getLog(YongyouBIPOperation.class);
// 授权模式客户端模式为client密码模式为password
private static final String grant_type = "client_credentials";
//第三方应用id对应系统中的app_id
private static final String client_id = "OA";
// 第三方应用秘钥对请求加签使用
private static final String client_secret = "9c462d924f6e42f4996b";
//访问的BIP系统的账套code
private static final String biz_center = "01";
//加密等级
private static final String secret_level = "L0";
//公钥加解密使用
private static final String pubKey = "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA0IwYK6tDUauBggUzzfBed9l5gP+iYCCbqWNbH5YQ0E+L+d8Q8nSCU7iwy88z/JhRiXqZJi77h5W3dVvP5jwLISYzrNq7g/jcQIZgKhAzWt2NpcojKAUk/RkKjrAlIshDf1RVdGmfkZCgo3MZfnhSKQHCVniEY2yjgYeIrq5xiHW+Bk5cEhYHKDsZsGQ/1yp9YnWJUOInTB2cxebwW3yYeCN6y7NQczywSwSrrFgzvfo3iDgTPSzA+VXuGRfisTxxDHkcT5sM2KeWvQhgNFKPtgKOU9jrv3UA+EkxRl76VWDG7XQomez/gYGlAyc6dahYv13SrLWGdIjnBgCcovEJ5wIDAQAB";
//认证接口地址
private static final String tokenUrl = "http://106.14.25.83:9999/nccloud/opm/accesstoken";
//付款单新增接口
private static final String payUrl = "http://106.14.25.83:9999/nccloud/api/arap/arap/paybill/insertandcommit";
// private static final String secret_level = "L0";
/**
* 操作执行加载单据数据包之前触发此事件在单据列表上执行单据操作传入的是单据内码
@ -285,31 +271,42 @@ public class YongyouBIPOperation extends AbstractOperationServicePlugIn implemen
}
private void handleForBIP(String eventName, DynamicObject payrequestinfo, boolean isnotext){
OkHttpClient client = new OkHttpClient();
//认证接口得到accesstoken
Request request = new Request.Builder().url(tokenUrl)
.post(createAccessTokenBody())
.header("Content-Type", "application/x-www-form-urlencoded")
.build();
// //认证接口得到accesstoken
// Request request = new Request.Builder().url(tokenUrl)
// .post(createAccessTokenBody())
// .header("Content-Type", "application/x-www-form-urlencoded")
// .build();
String accesstoken = null;
APICurUtils apiutil = new APICurUtils();//处理认证接口的工具类用友提供的第三方工具得到accesstoken
apiutil.init(DobeDWUtils.yyip,DobeDWUtils.yyport,DobeDWUtils.bizcenter,DobeDWUtils.clientid,DobeDWUtils.clientsecret,DobeDWUtils.pubKey,DobeDWUtils.clientid,null);
try {
Response response = client.newCall(request).execute();
JSONObject json_reuslt = JSON.parseObject(response.body().string());
accesstoken = json_reuslt.getString("accessToken");
String tokenresult = apiutil.getTokenByClient();
if(DobeDWUtils.isEmpty(tokenresult)){
log.error("用友认证接口返回的accessToken为空");
return;
}
JSONObject json_reuslt = JSON.parseObject(tokenresult);
if(json_reuslt.getJSONObject("data") == null){
log.error("用友认证接口返回的data为空");
return;
}
accesstoken = json_reuslt.getJSONObject("data").getString("access_token");
} catch (Exception e) {
log.error(String.format("用友认证接口异常:%s", e.getMessage()));
throw new RuntimeException(e);
}
if(DobeDWUtils.isEmpty(accesstoken)){
log.error("用友认证接口返回的accessToken为空");
return;
}
//处理合同付款申请单的审核推送用友bip组装付款入参
JSONObject payData = zzPayData(eventName,payrequestinfo,isnotext);
OkHttpClient client = new OkHttpClient();
//付款单新增接口上一步的accesstoken作为header
request = new Request.Builder().url(payUrl)
Request request = new Request.Builder().url(DobeDWUtils.payUrl)
.post(createFormRequestBody(payData))
.header("Content-Type", "application/x-www-form-urlencoded")
// .header("access_Token", accesstoken)
.header("access_Token", accesstoken)
.build();
String yynum = null;//用友单据编号
try {
@ -348,13 +345,22 @@ public class YongyouBIPOperation extends AbstractOperationServicePlugIn implemen
}
private RequestBody createAccessTokenBody() {
FormBody.Builder builder = new FormBody.Builder();
builder.add("grant_type", grant_type)
.add("client_id", client_id)
.add("client_secret", client_secret)
.add("biz_center", biz_center)
.add("secret_level", secret_level)
.add("pubKey", pubKey);
//如下写法在接口调用后用友反馈解密失败猜测是没有给RequestBody使用指定的MediaType 以及 没有使用json格式进行RequestBody设置
// try {
// String token = apiutil.getTokenByClient();
// String enptSecret = URLEncoder.encode(Encryption.pubEncrypt(pubKey,client_secret),"UTF-8");
// builder.add("grant_type", grant_type)
// .add("client_id", client_id)
// .add("client_secret", enptSecret)
// .add("biz_center", biz_center)
// .add("usercode", client_id)
// .add("groupcode", biz_center)
// .add("signature", SHA256Util.getSHA256(client_id+client_secret+pubKey,pubKey));
// } catch (Exception e) {
// throw new RuntimeException(e);
// }
return builder.build();
}

View File

@ -19,22 +19,6 @@ import java.util.Map;
public class YongyouBIPTask extends AbstractTask implements Plugin {
private static Log log = LogFactory.getLog(YongyouBIPTask.class);
// 授权模式客户端模式为client密码模式为password
private static final String grant_type = "client_credentials";
//第三方应用id对应系统中的app_id
private static final String client_id = "OA";
// 第三方应用秘钥对请求加签使用
private static final String client_secret = "9c462d924f6e42f4996b";
//访问的BIP系统的账套code
private static final String biz_center = "01";
//加密等级
private static final String secret_level = "L0";
//公钥加解密使用
private static final String pubKey = "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA0IwYK6tDUauBggUzzfBed9l5gP+iYCCbqWNbH5YQ0E+L+d8Q8nSCU7iwy88z/JhRiXqZJi77h5W3dVvP5jwLISYzrNq7g/jcQIZgKhAzWt2NpcojKAUk/RkKjrAlIshDf1RVdGmfkZCgo3MZfnhSKQHCVniEY2yjgYeIrq5xiHW+Bk5cEhYHKDsZsGQ/1yp9YnWJUOInTB2cxebwW3yYeCN6y7NQczywSwSrrFgzvfo3iDgTPSzA+VXuGRfisTxxDHkcT5sM2KeWvQhgNFKPtgKOU9jrv3UA+EkxRl76VWDG7XQomez/gYGlAyc6dahYv13SrLWGdIjnBgCcovEJ5wIDAQAB";
//认证接口地址
private static final String tokenUrl = "http://106.14.25.83:8090/nccloud/opm/accesstoken";
//付款金额查询接口
private static final String payUrl = "http://106.14.25.83:8090/nccloud/api/arap/arap/paybill/insertandcommit";
//合同付款申请单的实体名称
private static final String payrequestEntity = "recon_payreqbill";
//费用登记的实体名称

View File

@ -10,11 +10,32 @@ import java.text.SimpleDateFormat;
import java.util.Date;
public class DobeDWUtils {
//数仓相关的工具类 数仓接口url和appcode在此申明
//数仓和用友相关的工具类 数仓和用友接口url和appcode在此申明
//数仓接口的appCode 可能会更换
public static final String appCode = "AppCode 895894e0-73de-40a9-9b1f-e87fe35a13fd";
//数仓接口地址基本信息
public static final String dwUrl = "http://106.14.120.215:8080/webroot/service/publish/7e9d818c-43c0-47cf-ad4c-40c66b92bb34/";
public static final MediaType MTJSON = MediaType.get("application/json");
//授权模式客户端模式为client密码模式为password
public static final String granttype = "client_credentials";
//第三方应用id对应系统中的app_id
public static final String clientid = "ISC";
// 第三方应用秘钥对请求加签使用
public static final String clientsecret = "72135b74ab7046dbab06";
//访问的BIP系统的账套code
public static final String bizcenter = "01";
//公钥加解密使用
public static final String pubKey = "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAtifU2Nm6/lwYybVGNMzmn/UvOmtjqs9tuesdchx0pK6HsiubCRiFKr/TFGLHhBKJ3TXtH4gwJLkGrMJRdTicWHOCAwcU9hmM+XsHCF4FQ4UWcWA73Ha9qR3SC1tSxwDw8n2/uHUKtKzlOGuJQnzL5hBN7DnDU4M7FqEZ+ctG71ufkjytY1TKVoHfThRTAP1ouSNo3gM/pMwjISTkFH5vY7twdu9IW09+S5/uo8C+pw7BahDpOv5z7F1yWDEnw1sdwNdqPFV2DsB1JS3GfLe9P3ZACeR+lcD3KrwBsQky3oZsg3y6NsDqOpzoLk9pToFzmci1GMfCKoc4MzVF9fq7XQIDAQAB";
//接口IP地址
public static final String yyip = "106.14.25.83";
//接口端口
public static final String yyport = "9999";
//用友付款单新增接口
public static final String payUrl = "http://106.14.25.83:9999/nccloud/api/arap/arap/paybill/insertandcommit";
//付款金额查询接口
private static final String payQueryUrl = "http://106.14.25.83:8090/nccloud/api/arap/arap/paybill/insertandcommit";
public static boolean isEmpty(String value) {
return value == null || value.trim().length() <= 0;
}