Commit ac4602b5 authored by Luochenglong's avatar Luochenglong

Merge remote-tracking branch 'origin/develop' into develop

parents 39d0d100 eb1c4262
package com.hand.hlcm;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.NameValuePair;
import org.apache.commons.httpclient.methods.PostMethod;
import org.apache.commons.httpclient.methods.RequestEntity;
import org.apache.commons.httpclient.methods.StringRequestEntity;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URLDecoder;
import java.nio.charset.Charset;
import java.util.Base64;
/**
* description
*
* @author Administrator 2023/01/03 15:07
*/
public class HttpPostUtil {
public static String httpPostGetToken(String postUrl,String appId,String appSecret){
try {
PostMethod postMethod = null;
postMethod = new PostMethod(postUrl) ;
postMethod.setRequestHeader("Content-Type", "application/x-www-form-urlencoded") ;
postMethod.setRequestHeader("Authorization", "Basic "+ Base64.getUrlEncoder().encodeToString((appId + ":" + appSecret).getBytes())) ;
//参数设置,需要注意的就是里边不能传NULL,要传空字符串
NameValuePair[] data = {
new NameValuePair("grant_type","client_credentials"),
new NameValuePair("scope","write")
};
postMethod.setRequestBody(data);
HttpClient httpClient = new HttpClient();
// 执行POST方法
int response = httpClient.executeMethod(postMethod);
String result = postMethod.getResponseBodyAsString() ;
return result;
} catch (Exception e) {
return "{\n" +
" \"error\": \"interError\",\n" +
" \"message\": \"请求接口失败\",\n" +
" \"path\": \"/oauth/token\"\n" +
"}";
}
}
public static void main(String[] args) throws Exception {
String resPonse=httpPostGetToken("http://apistage.huilianyi.com/gateway/oauth/token","a92074ce-ff45-409e-8ff9-3516415d8f82","NTY4ZmUyY2QtOTc3YS00MTU0LWIxNTEtYmZiNjQ5M2ZjYjY0");
System.out.println(resPonse);
}
}
<?xml version="1.0" encoding="UTF-8"?>
<!--
$Author: zhangxing5129
$Date: 2014-7-14 下午03:09:37
$Revision: 1.0
$Purpose:
-->
<bm:model xmlns:o="leaf.database.local.oracle" xmlns:bm="http://www.leaf-framework.org/schema/bm" xmlns:f="leaf.database.features" needAccessControl="false">
<bm:operations>
<bm:operation name="query">
<bm:query-sql><![CDATA[
SELECT t.access_token
FROM (SELECT v.record_id, v.access_token
FROM token_record_info v
where v.start_time <= sysdate
and v.over_time >= sysdate
order by v.record_id desc) t
where rownum = 1
]]></bm:query-sql>
</bm:operation>
<bm:operation name="update">
<bm:update-sql><![CDATA[
begin
token_post_pkg.insert_token_recode(p_system_source =>${@system_source},
p_expires_in =>${@expires_in},
p_access_token =>${@access_token},
p_user_id => ${/session/@user_id}
);
end;]]></bm:update-sql>
</bm:operation>
<bm:operation name="execute">
<bm:update-sql><![CDATA[begin
${@check_token_valid}:= token_post_pkg.check_token_valid;
end;]]></bm:update-sql>
<bm:parameters>
<bm:parameter name="check_token_valid" output="true" outputPath="@check_token_valid"/>
</bm:parameters>
</bm:operation>
<bm:operation name="insert">
<bm:update-sql><![CDATA[
begin
insert into token_response_logs
(
log_id,
response_json,
status,
created_by,
creation_date,
last_updated_by,
last_update_date
) values
(token_response_logs_s.nextval,
${@json},
${@status},
${/session/@user_id},
sysdate,
${/session/@user_id},
sysdate
);
commit;
end;]]></bm:update-sql>
</bm:operation>
</bm:operations>
<bm:fields>
<bm:field name="access_token"/>
</bm:fields>
</bm:model>
importClass(Packages.com.hand.hlcm.HttpPostUtil);
importPackage(Packages.java.io);
importPackage(Packages.java.util);
//importClass(Packages.leaf.plugin.util.Base64);
function httpPostGetToken(postUrl,appId,appSecret) {
try {
var result = new HttpPostUtil().httpPostGetToken(postUrl,appId,appSecret);
return result;
} catch (e) {
println(e);
return false;
}
}
\ No newline at end of file
......@@ -89,7 +89,7 @@
<a:field name="wfl_status" />
</a:fields>
</a:dataSet>
<a:dataSet id="hls_journal_header_result_ds" autoPageSize="true" autoQuery="true" model="hls.HLS536.hls_journal_import_header" queryDataSet="hls_journal_header_query" selectable="true">
<a:dataSet id="hls_journal_header_result_ds" autoPageSize="true" autoQuery="true" model="hls.HLS536.hls_journal_import_header_wfl" queryDataSet="hls_journal_header_query" selectable="true">
</a:dataSet>
</a:dataSets>
<a:screenBody>
......
<?xml version="1.0" encoding="UTF-8"?>
<a:service xmlns:p="uncertain.proc" xmlns:a="http://www.leaf-framework.org/application" xmlns:s="leaf.plugin.script" trace="true">
<a:init-procedure>
<s:server-script import="token_record.js"><![CDATA[
try {
var sys_url_bm = $bm('cont.CON4000.get_sys_url');
var parameter_code = 'TOKEN_POSTURL';
var SysposturlQuery = sys_url_bm.queryAsMap({
parameter_code: parameter_code
});
var posturl = SysposturlQuery.getChildren()[0].parameter_value;
var parameter_code = 'TOKEN_APPID';
var SysappidQuery = sys_url_bm.queryAsMap({
parameter_code: parameter_code
});
var token_appid = SysappidQuery.getChildren()[0].parameter_value;
var parameter_code = 'TOKEN_APPSECRET';
var SysappsecretQuery = sys_url_bm.queryAsMap({
parameter_code: parameter_code
});
var token_appsecret = SysappsecretQuery.getChildren()[0].parameter_value;
var token_savelogs_bm = $bm('token.TOKEN001.token_savelogs');
token_savelogs_bm.execute;
var check_token_valid = $ctx.current_parameter.check_token_valid;
if (check_token_valid = 'true') {
var SystokenQuery = token_savelogs_bm.queryAsMap();
var access_token = SystokenQuery.getChildren()[0].access_token;
} else {
var data = httpPostGetToken(posturl, token_appid, token_appsecret);
var json = JSON.parse(data);
var access_token = json.access_token;
var status = json.status;
if (access_token) {
token_savelogs_bm.insert({
'json': data,
'status': 'success'
})
token_savelogs_bm.update({
'system_source': 'hlcm',
'expires_in': json.expires_in,
'access_token': access_token
})
}
if (status) {
var token_savelogs_bm = $bm('token.TOKEN001.token_savelogs');
token_savelogs_bm.insert({
'json': json,
'status': 'fail'
});
}
}
} catch (e) {
println('e:' + e);
}
]]></s:server-script>
</a:init-procedure>
</a:service>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment