对接小程序接口

wenjuan
yanzai 1 year ago
parent 67d60a6714
commit cad351a57a

@ -23,7 +23,7 @@ class HomeController extends Controller
public function config() public function config()
{ {
$hospitals = DB::table('hospitals') $hospitals = DB::table('hospitals')
->select("id", "name", "latitude", "longitude", "logo") ->select("id", "name", "latitude", "longitude", "logo","address")
->where(['status' => 1, 'is_del' => 0])->get(); ->where(['status' => 1, 'is_del' => 0])->get();
if (count($hospitals) < 1) return \Yz::echoError1(''); if (count($hospitals) < 1) return \Yz::echoError1('');
$db_config = DB::table('configs')->whereIn('label', ['首页欢迎词', '首页banner'])->get(); $db_config = DB::table('configs')->whereIn('label', ['首页欢迎词', '首页banner'])->get();
@ -49,7 +49,7 @@ class HomeController extends Controller
], [ ], [
'message' => '', 'message' => '',
'name' => '单位体检预约', 'name' => '单位体检预约',
'jump' => '/pages/main/cjwt/cjwt', 'jump' => '/pages/main/optionalProject/choose',
'icon' => '/assets/h5/tuanjianyuyue.png' 'icon' => '/assets/h5/tuanjianyuyue.png'
]], ]],
'button' => [[[ 'button' => [[[

@ -103,6 +103,7 @@ class PayController extends Controller
'orderid'=>$orderInfo->order_number, 'orderid'=>$orderInfo->order_number,
'refund_order_id'=>'T'.$orderInfo->order_number, 'refund_order_id'=>'T'.$orderInfo->order_number,
'refund_amount'=>(int)($orderInfo->true_price * 100), 'refund_amount'=>(int)($orderInfo->true_price * 100),
'refund_reason'=>"体检H5订单退款",
]; ];
$XCX = new XCXApiController(); $XCX = new XCXApiController();
$res = $XCX::Post('订单退款', $data); $res = $XCX::Post('订单退款', $data);

@ -36,6 +36,8 @@ class UserController extends Controller
$info = [ $info = [
'name' => isset($default_person->name)? $default_person->name:null, 'name' => isset($default_person->name)? $default_person->name:null,
'sex' => isset($default_person->sex)?$default_person->sex:null, 'sex' => isset($default_person->sex)?$default_person->sex:null,
'phone'=>$default_person->phone,
'id_number'=>$default_person->id_number,
'count' => $count, 'count' => $count,
'openid' => $openid, 'openid' => $openid,
]; ];
@ -98,6 +100,16 @@ class UserController extends Controller
} }
public function tttt(){
$XCX=new XCXApiController();
$data=[
'wxid'=>'oosgJj-SVIxTrm_g1p213tsSHK5g'
];
$res=$XCX::Post('就诊人列表',$data);
$ApiPersonList=$res['data'];
// dd($ApiPersonList[0]);
$XCX::XCXDecode($ApiPersonList[0]['idNumber']);
}
//更新用户列表,调用远程小程序接口 //更新用户列表,调用远程小程序接口
public function UpdatePersonList($openid) public function UpdatePersonList($openid)
{ {
@ -105,26 +117,28 @@ class UserController extends Controller
$data=[ $data=[
'wxid'=>$openid 'wxid'=>$openid
]; ];
$list=$XCX::Post('就诊人列表',$data); // $res=$XCX::Post('就诊人列表',$data);
// $ApiPersonList=$res['data'];
// dd($ApiPersonList);
$ApiPersonList = [ $ApiPersonList = [
[ [
'ghzid' => 'ghz11', 'ghzid' => 'ghz11',
'id_number'=>'15210219920524154X', 'idNumber'=>'15210219920524154X',
'name' => '周京京', 'name' => '周京京',
'phone' => '11111111111', 'phone' => '11111111111',
'sex' => '1', 'sex' => '1',
'birthday' => '1989-01-01', 'birthday' => '1989-01-01',
'patient_type' => '0', 'patientType' => '0',
'marriage' => '1', 'marriage' => '1',
], ],
[ [
'ghzid' => 'ghz22', 'ghzid' => 'ghz22',
'id_number'=>'1132112432432', 'idNumber'=>'460026199002190013',
'name' => '测试2', 'name' => '测试2',
'phone' => '222222222', 'phone' => '222222222',
'sex' => '1', 'sex' => '1',
'birthday' => '1990-01-01', 'birthday' => '1990-01-01',
'patient_type' => '1', 'patientType' => '1',
'marriage' => '1', 'marriage' => '1',
] ]
]; ];
@ -145,16 +159,23 @@ class UserController extends Controller
$onlyInApi = array_diff($api_person_ghzids, $db_person_ghzids); $onlyInApi = array_diff($api_person_ghzids, $db_person_ghzids);
$success_count=0; $success_count=0;
foreach ($ApiPersonList as $apiperson) { foreach ($ApiPersonList as $apiperson) {
$marriage=0;
if($apiperson['marriage']=='未婚'){
$marriage=2;
}
if($apiperson['marriage']=='已婚'){
$marriage=1;
}
$personInfo = [ $personInfo = [
'ghzid' => $apiperson['ghzid'], 'ghzid' => $apiperson['ghzid'],
'id_number' => $apiperson['id_number'], 'id_number' => $apiperson['idNumber'],
'name' => $apiperson['name'], 'name' => $apiperson['name'],
'birthday' => $apiperson['birthday'], 'birthday' => $apiperson['birthday'],
'sex' => $apiperson['sex'], 'sex' => $apiperson['sex'],
'phone' => $apiperson['phone'], 'phone' => $apiperson['phone'],
'married' => $apiperson['marriage'], 'married' =>$marriage,
'user_id' => $user->id, 'user_id' => $user->id,
'patient_type' => $apiperson['patient_type'], 'patient_type' => $apiperson['patientType'],
'updated_at'=>date('Y-m-d H:i:s') 'updated_at'=>date('Y-m-d H:i:s')
]; ];
if (in_array($apiperson['ghzid'], $intersection)) {//双方都有的,更新 if (in_array($apiperson['ghzid'], $intersection)) {//双方都有的,更新

@ -4,6 +4,7 @@ namespace App\Http\Controllers\API;
use App\Http\Controllers\Controller; use App\Http\Controllers\Controller;
use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Schema\Blueprint;
use Illuminate\Http\Exceptions\HttpResponseException;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Http; use Illuminate\Support\Facades\Http;
@ -28,16 +29,17 @@ class XCXApiController extends Controller
public static function Post($url_code, $data) public static function Post($url_code, $data)
{ {
$url_address = self::Api($url_code); $url_address = self::Api($url_code);
self::RequestLog(self::$baseUrl.$url_address, $data, $url_code, '小程序接口'); self::RequestLog(self::$baseUrl . $url_address, $data, $url_code, '小程序接口');
$timestamp = time(); $timestamp = time();
$nonce = md5(uniqid(rand(), true)); $nonce = md5(uniqid(rand(), true));
$base64Signature = self::Sign( $url_address, $data, $nonce, $timestamp); $base64Signature = self::Sign($url_address, $data, $nonce, $timestamp);
$response = Http::withHeaders([ $response = Http::withHeaders([
'Authorization' => self::BuildAuthorization($nonce, $timestamp, $base64Signature) 'Authorization' => self::BuildAuthorization($nonce, $timestamp, $base64Signature)
])->post(self::$baseUrl.$url_address, $data); ])->post(self::$baseUrl . $url_address, $data);
// dd($response); // dd(self::BuildAuthorization($nonce, $timestamp, $base64Signature));
if ($response->successful()) { if ($response->successful()) {
// 处理成功的响应 // 处理成功的响应
$res_string = json_encode($response->json(), JSON_UNESCAPED_UNICODE); $res_string = json_encode($response->json(), JSON_UNESCAPED_UNICODE);
@ -48,11 +50,21 @@ class XCXApiController extends Controller
if ($str_size > 10) $save_res = '{"data":"Row size too large"}'; if ($str_size > 10) $save_res = '{"data":"Row size too large"}';
self::$request->response_data = $save_res; self::$request->response_data = $save_res;
self::$request->save(); self::$request->save();
} else {
$res = json_decode($res_string, true);
if (!$res['success']) {
throw new HttpResponseException(\Yz::echoError1("小程序接口提示:" . $res['message']));
}
return [
'code' => $res['code'],
'message' => $res['message'],
'data' => $res['result']
];
} else {
// 处理失败的响应 // 处理失败的响应
self::$request->response_data = "请求失败"; self::$request->response_data = "请求小程序接口失败";
self::$request->save(); self::$request->save();
throw new HttpResponseException(\Yz::echoError1("请求小程序接口失败"));
} }
} }
@ -105,7 +117,7 @@ class XCXApiController extends Controller
} }
//计算签名和 Authorization //计算签名和 Authorization
public static function Sign($url, $data, $nonce, $timestamp,$is_urlencode=false) public static function Sign($url, $data, $nonce, $timestamp, $is_urlencode = false)
{ {
$body = self::buildSortedQueryString($data); $body = self::buildSortedQueryString($data);
@ -122,18 +134,18 @@ class XCXApiController extends Controller
$url . "\n" . $url . "\n" .
$timestamp . "\n" . $timestamp . "\n" .
$nonce . "\n" . $nonce . "\n" .
$body; urldecode($body) . "\n";
//dd($SignStr);
// 使用私钥进行 RSA 签名 // 使用私钥进行 RSA 签名
openssl_sign($SignStr, $signature, $private_key, OPENSSL_ALGO_SHA256); openssl_sign($SignStr, $signature, $private_key, OPENSSL_ALGO_SHA256);
if($is_urlencode){ if ($is_urlencode) {
$signature= urlencode($signature); $signature = urlencode($signature);
} }
// 对签名结果进行 Base64 编码 // 对签名结果进行 Base64 编码
$base64Signature = base64_encode($signature); $base64Signature = base64_encode($signature);
// dd($base64Signature); // dd($SignStr,$base64Signature);
return $base64Signature; return $base64Signature;
} }
@ -146,5 +158,21 @@ class XCXApiController extends Controller
return self::$signType . ' ' . $signInfo; return self::$signType . ' ' . $signInfo;
} }
//解密
public static function XCXDecode($str)
{
$private_key = Storage::get('keys/private_key.pem');
$str = "mZd4Nds9jyKxGfjId+eQAQ3WBMZbjEZg4Plq2Qz62W+AZvcDCAjkOL8VRAxNWXTwsrCNkMf07tMoY1NPzPgob00SfOJwVeM7SxqwH4PWKqkm5+Rg4g+eciepst66ToPI2ArgZutnb3XlcOqF8Mzlvz53GgDe/6VFQDaFATj1DOrEMyPgF85FY18lHWH5HKC1ctOMC/FTwTISJ0QPMSpYiBu8hWr4mTkYzY5nFkxv+M4q30IeAvJocCuIFnEa8t8iU6cvixe0HJofLug7fJJb8PEwPhJRMIocME1knETKszhI7YgSBj9RlBkwzLhtG2RCCZbHiK4UOK7HrvthXyJI/A==";
$str = base64_decode($str);
// dd($str);
if (openssl_private_decrypt($str, $decryptedData, $private_key, OPENSSL_PKCS1_OAEP_PADDING)) {
dd($decryptedData);
return $decryptedData;
} else {
throw new HttpResponseException(\Yz::echoError1("解密数据失败"));
}
}
} }

@ -68,6 +68,8 @@ Route::group(['prefix' => 'api/H5'], function () {
//测试---------------------------- //测试----------------------------
Route::post('/Finish_test', 'App\Http\Controllers\API\H5\OrderController@Finish_test');//测试 Route::post('/Finish_test', 'App\Http\Controllers\API\H5\OrderController@Finish_test');//测试
Route::post('/tttt', 'App\Http\Controllers\API\H5\UserController@tttt');//测试
}); });

@ -15,6 +15,7 @@
import { import {
onShow onShow
} from '@dcloudio/uni-app' } from '@dcloudio/uni-app'
import wx from 'weixin-js-sdk'
import { import {
useStore useStore
} from '@/store' } from '@/store'
@ -186,6 +187,15 @@
} }
} }
} }
const OpenMap=()=>{
console.log($store.config.hospital[0]);
let hospital=$store.config.hospital[0];
let p='&longitude='+hospital.longitude+'&latitude='+hospital.latitude+'&name='+hospital.name+'&address='+hospital.address+'&scale=16'+'&type=gcj02'
console.log(p);
wx.miniProgram.navigateTo({
url: '/pages/other/entry/index?path=/pages/physical-examination/location/index'+p
})
};
onShow(() => { onShow(() => {
if (!!user_box_ref.value) { if (!!user_box_ref.value) {
@ -206,7 +216,7 @@
<view class="map_icon_wrapper"> <view class="map_icon_wrapper">
<image src="@/static/assets/dingwei.png"></image> <image src="@/static/assets/dingwei.png"></image>
</view> </view>
<view class="map_name_wrapper">{{ hospital_info.name }}</view> <view class="map_name_wrapper" @click="OpenMap()">{{ hospital_info.name }}</view>
<view v-if="!!hospital_info.long" class="map_long_wrapper">{{ hospital_info.long }}km</view> <view v-if="!!hospital_info.long" class="map_long_wrapper">{{ hospital_info.long }}km</view>
</view> </view>
<view class="logo_wrapper"> <view class="logo_wrapper">

@ -26,7 +26,7 @@
}) })
uni.hideLoading() uni.hideLoading()
$response(response, () => { $response(response, () => {
console.log(response);
}) })
} }
onLoad((option) => { onLoad((option) => {

@ -51,6 +51,17 @@
order_info.value.status = 3 order_info.value.status = 3
} }
} }
const StartPay=async(id)=>{//
uni.showLoading()
const response = await $api('StartPay' ,{
openid: localStorage.getItem('OPENID'),
id: id,
})
uni.hideLoading()
$response(response, () => {
order_list.value = response.data.list
})
}
onMounted(() => { onMounted(() => {
deepInfo() deepInfo()
@ -117,7 +128,7 @@
</view> </view>
</view> </view>
<view class="order_pay_button_wrapper"> <view class="order_pay_button_wrapper">
<view v-if="[1].includes(order_info.status)" class="button_item_wrapper pay_button_wrapper"></view> <view v-if="[1].includes(order_info.status)" @click="StartPay(order_info.id)" class="button_item_wrapper pay_button_wrapper"></view>
<view v-if="[2].includes(order_info.status)" class="button_item_wrapper change_button_wrapper"></view> <view v-if="[2].includes(order_info.status)" class="button_item_wrapper change_button_wrapper"></view>
<view v-if="[2].includes(order_info.status)" class="button_item_wrapper refund_button_wrapper">退</view> <view v-if="[2].includes(order_info.status)" class="button_item_wrapper refund_button_wrapper">退</view>
<view v-if="[4].includes(order_info.status) && order_info.report" <view v-if="[4].includes(order_info.status) && order_info.report"

Loading…
Cancel
Save