Paypal开发者中心获取“ClientId”和“ClientSecret”参数

正式环境设置

1、登录到 paypal开发者中心
网址:https://developer.paypal.com/developer/
点击右上角登录按钮登录

2、左侧栏 - 我的应用程序和凭证 - 点击“创建新应用”
新注册的paypal账号,需要进行邮箱验证,验证通过后,需要等待一段时间(或重新登录),才会出现相关设置项位置
在这里插入图片描述
验证邮箱通过后,点击创建新应用
在这里插入图片描述
3、按提示填写,保存创建应用
在这里插入图片描述
4、点击刚创建的应用进入应用详情页
在这里插入图片描述
5、应用详情页获得网站开发人员所需要的“ClientId”和“ClientSecret”参数
在这里插入图片描述
6、应用详情页下方创建WEBHOOKS
在这里插入图片描述
在这里插入图片描述
7、设置完成后,把“ClientId”和“ClientSecret”参数提供给网站开发人员即可。

**

以下是沙盒测试环境使用设置

**
点击左侧栏沙盒账号,点击创建新的测试账号
在这里插入图片描述
按提示创建测试账号
在这里插入图片描述
创建沙箱应用
在这里插入图片描述
在这里插入图片描述
之后的设置与正式环境一样获取“ClientId”和“ClientSecret”参数及相关设置

再创建一个Personal个人沙箱账户就可以用来测试付款订单及回调处理订单等业务了

在只知道大华平台地址、用户名、密码、ClientIdClientSecret的情况下,可以通过调用大华平台提供的接口获取视频地址,再通过上面提供的Java代码将视频下载到本地。 以下是一个示例代码,可以作为参考: ```java import java.io.FileOutputStream; import java.io.InputStream; import java.net.HttpURLConnection; import java.net.URL; import java.net.URLEncoder; import java.util.Base64; public class DownloadVideo { public static void main(String[] args) { String apiUrl = "http://xxx.xxx.xxx.xxx"; String username = "your_username"; String password = "your_password"; String clientId = "your_client_id"; String clientSecret = "your_client_secret"; String cameraIndexCode = "your_camera_index_code"; // 摄像头编号 String savePath = "D:/video.mp4"; // 保存路径 try { // 获取AccessToken String accessToken = getAccessToken(apiUrl, clientId, clientSecret, username, password); // 获取视频地址 String videoUrl = getVideoUrl(apiUrl, accessToken, cameraIndexCode); // 下载视频 URL url = new URL(videoUrl); HttpURLConnection conn = (HttpURLConnection) url.openConnection(); conn.setConnectTimeout(5 * 1000); conn.setRequestMethod("GET"); conn.setRequestProperty("Charset", "UTF-8"); conn.setRequestProperty("Connection", "Keep-Alive"); conn.setRequestProperty("Authorization", "Bearer " + accessToken); InputStream inputStream = conn.getInputStream(); byte[] getData = readInputStream(inputStream); FileOutputStream fos = new FileOutputStream(savePath); fos.write(getData); if (fos != null) { fos.close(); } if (inputStream != null) { inputStream.close(); } System.out.println("视频下载完成"); } catch (Exception e) { e.printStackTrace(); } } public static String getAccessToken(String apiUrl, String clientId, String clientSecret, String username, String password) throws Exception { String authUrl = apiUrl + "/artemis/api/auth/token?appKey=" + clientId + "&appSecret=" + clientSecret; URL url = new URL(authUrl); HttpURLConnection conn = (HttpURLConnection) url.openConnection(); conn.setConnectTimeout(5 * 1000); conn.setRequestMethod("POST"); conn.setRequestProperty("Charset", "UTF-8"); conn.setRequestProperty("Content-Type", "application/json"); conn.setRequestProperty("Connection", "Keep-Alive"); conn.setDoOutput(true); conn.setDoInput(true); String authString = username + ":" + password; String authStringEnc = Base64.getEncoder().encodeToString(authString.getBytes("utf-8")); conn.setRequestProperty("Authorization", "Basic " + authStringEnc); String params = "{\"grantType\":\"password\",\"username\":\"" + username + "\",\"password\":\"" + password + "\"}"; byte[] postData = params.getBytes("utf-8"); conn.getOutputStream().write(postData); InputStream inputStream = conn.getInputStream(); byte[] getData = readInputStream(inputStream); String result = new String(getData, "utf-8"); String accessToken = ""; if (result.contains("accessToken")) { String[] arr = result.split(","); for (String str : arr) { if (str.contains("accessToken")) { accessToken = str.split(":")[1].replaceAll("\"", ""); break; } } } return accessToken; } public static String getVideoUrl(String apiUrl, String accessToken, String cameraIndexCode) throws Exception { String url = apiUrl + "/artemis/api/video/v1/cameras/" + URLEncoder.encode(cameraIndexCode, "utf-8") + "/previewURLs"; HttpURLConnection conn = (HttpURLConnection) new URL(url).openConnection(); conn.setConnectTimeout(5 * 1000); conn.setRequestMethod("GET"); conn.setRequestProperty("Charset", "UTF-8"); conn.setRequestProperty("Content-Type", "application/json"); conn.setRequestProperty("Connection", "Keep-Alive"); conn.setRequestProperty("Authorization", "Bearer " + accessToken); InputStream inputStream = conn.getInputStream(); byte[] getData = readInputStream(inputStream); String result = new String(getData, "utf-8"); String videoUrl = ""; if (result.contains("url")) { String[] arr = result.split(","); for (String str : arr) { if (str.contains("url")) { videoUrl = str.split(":")[1].replaceAll("\"", ""); break; } } } return videoUrl; } public static byte[] readInputStream(InputStream inputStream) throws Exception { byte[] buffer = new byte[1024]; int len; ByteArrayOutputStream bos = new ByteArrayOutputStream(); while ((len = inputStream.read(buffer)) != -1) { bos.write(buffer, 0, len); } bos.close(); return bos.toByteArray(); } } ``` 上面的代码中,我们首先调用`getAccessToken()`方法获取AccessToken,然后调用`getVideoUrl()`方法获取视频地址,最后通过调用`downloadVideo()`方法将视频下载到本地。需要注意的是,视频地址返回的是一个JSON字符串,需要对字符串进行解析获取实际可用的视频地址。另外,需要将摄像头编号替换成实际可用的编号。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

每天都进步一点点

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值