Paypal设置获得“ClientId”和“ClientSecret”参数

注意:设置的paypal账号应当为个人的新版账号或者business账号,个人的旧版账号无法设置,可联系paypal客服进行账号升级
设置paypal支付前,请确认网站是否有安装ssl证书,即链接前面为“https”

1.登录到 paypal开发者中心
https://developer.paypal.com/developer/

2.进入设置页面

3.点击左侧栏的“SANDBOX”下的“Accounts”选项后,再点击右侧“Create Account”按钮进行创建新的测试账号

4.按照以下提示填写内容,最后并点击保存

5.点击左侧栏的“DASHBOARD”下的“My Apps & Credentials”选项后,右侧版面的“REST API apps”的标题下,切换到“Live”状态,点击“Create App”按钮进行创建新的App账号
注意:新注册的paypal账号,需要进行邮箱验证,才有“live”的设置的位置
验证通过后,需要等待一段时间,才会出现设置的位置

6.按照以下提示填写内容,最后并点击保存

7.进入设置页面,在“LIVE WEBHOOKS”的标题下,点击“Add webhook”进行创建webhooks

8.按照以下提示填写内容,最后并点击保存

9.填写上“域名/?do_action=user.user_oauth&Type=Paypal”

10.勾选以下选项

11.勾选以下选项

12.填写上“域名/?do_action=user.user_oauth&Type=Paypal”,最后点击保存

13.上述设置保存后,可以分别获得“ClientId”和“ClientSecret”参数

在只知道大华平台地址、用户名、密码、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字符串,需要对字符串进行解析获取实际可用的视频地址。另外,需要将摄像头编号替换成实际可用的编号。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值