update structure

This commit is contained in:
2024-09-23 09:00:24 +07:00
parent f29ba21c97
commit 7ee1e022bc
6 changed files with 16 additions and 7 deletions

View File

@@ -24,7 +24,10 @@ func GetJadwalDokter(c *gin.Context) {
c.JSON(http.StatusInternalServerError, err)
}
subspesialis, err := dokter.GetSubspesialis()
if err != nil {
c.JSON(http.StatusInternalServerError, err)
}
conf := config.ConfigBpjs{}
@@ -48,10 +51,7 @@ func GetJadwalDokter(c *gin.Context) {
c.JSON(http.StatusInternalServerError, err)
}
for _, key := range *res {
key.KodeDokter
}
err = dokter.
date, errParse := time.Parse("2006-01-02", tanggal)
if errParse != nil {
c.JSON(http.StatusInternalServerError, errParse)

View File

@@ -0,0 +1,39 @@
package Vclaim
import (
"crypto/hmac"
"crypto/sha256"
"encoding/base64"
"encoding/hex"
"fmt"
"log"
"time"
)
type ConfigBpjs struct {
Cons_id string
Secret_key string
User_key string
}
func SetHeader(cfg ConfigBpjs) (string, string, string, string, string) {
timenow := time.Now().UTC()
t, err := time.Parse(time.RFC3339, "1970-01-01T00:00:00Z")
if err != nil {
log.Fatal(err)
}
tstamp := timenow.Unix() - t.Unix()
secret := []byte(cfg.Secret_key)
message := []byte(cfg.Cons_id + "&" + fmt.Sprint(tstamp))
hash := hmac.New(sha256.New, secret)
hash.Write(message)
// to lowercase hexits
hex.EncodeToString(hash.Sum(nil))
// to base64
X_signature := base64.StdEncoding.EncodeToString(hash.Sum(nil))
return cfg.Cons_id, cfg.Secret_key, cfg.User_key, fmt.Sprint(tstamp), X_signature
}

View File

@@ -0,0 +1,50 @@
package Vclaim
import (
"crypto/aes"
"crypto/cipher"
"crypto/sha256"
"encoding/base64"
"errors"
"bridging-rssa/docs"
lzstring "github.com/daku10/go-lz-string"
)
func ResponseVclaim(encrypted string, key string) (string, error) {
cipherText, err := base64.StdEncoding.DecodeString(encrypted)
if err != nil {
return "", err
}
hash := sha256.Sum256([]byte(key))
block, err := aes.NewCipher(hash[:])
if err != nil {
return "", err
}
if len(cipherText) < aes.BlockSize {
return "", errors.New("cipherText too short")
}
iv := hash[:aes.BlockSize]
if len(cipherText)%aes.BlockSize != 0 {
return "", errors.New("cipherText is not a multiple of the block size")
}
mode := cipher.NewCBCDecrypter(block, iv)
mode.CryptBlocks(cipherText, cipherText)
// cipherText, _ = pkcs7.Unpad(cipherText, aes.BlockSize)
cipherText = docs.RemovePKCS7Padding(cipherText)
data, err := lzstring.DecompressFromEncodedURIComponent(string(cipherText))
// data, err := helper.DecompressFromEncodedUriComponent(string(cipherText))
if err != nil {
return "", err
}
return data, nil
}

View File

@@ -0,0 +1,122 @@
package Vclaim
import (
"bytes"
"encoding/json"
"fmt"
"io"
"io/ioutil"
"log"
"net/http"
"github.com/mashingan/smapping"
)
type Respon_MentahDTO struct {
MetaData struct {
Code string `json:"code"`
Message string `json:"message"`
} `json:"metaData"`
Response string `json:"response"`
}
type Respon_DTO struct {
MetaData struct {
Code string `json:"code"`
Message string `json:"message"`
} `json:"metaData"`
Response interface{} `json:"response"`
}
func GetRequest(endpoint string, cfg interface{}) interface{} {
conf := ConfigBpjs{}
err := smapping.FillStruct(&conf, smapping.MapFields(&cfg))
if err != nil {
log.Fatalf("Failed map %v: ", err)
}
cons_id, Secret_key, User_key, tstamp, X_signature := SetHeader(conf)
req, _ := http.NewRequest("GET", endpoint, nil)
req.Header.Add("Content-Type", "Application/x-www-form-urlencoded")
req.Header.Add("X-cons-id", cons_id)
req.Header.Add("X-timestamp", tstamp)
req.Header.Add("X-signature", X_signature)
req.Header.Add("user_key", User_key)
res, err := http.DefaultClient.Do(req)
if err != nil {
fmt.Println(err)
}
body, err := io.ReadAll(res.Body)
if err != nil {
fmt.Println(err)
}
var resp_mentah Respon_MentahDTO
var resp Respon_DTO
json.Unmarshal([]byte(body), &resp_mentah)
resp_decrypt, _ := ResponseVclaim(string(resp_mentah.Response), string(cons_id+Secret_key+tstamp))
resp.MetaData = resp_mentah.MetaData
json.Unmarshal([]byte(resp_decrypt), &resp.Response)
return &resp
}
func PostRequest(endpoint string, cfg interface{}, data interface{}) interface{} {
conf := ConfigBpjs{}
err := smapping.FillStruct(&conf, smapping.MapFields(&cfg))
if err != nil {
log.Fatalf("Failed map %v: ", err)
}
cons_id, Secret_key, User_key, tstamp, X_signature := SetHeader(conf)
var buf bytes.Buffer
err = json.NewEncoder(&buf).Encode(data)
if err != nil {
log.Fatal(err)
}
req, _ := http.NewRequest("POST", endpoint, &buf)
req.Header.Add("Content-Type", "Application/x-www-form-urlencoded")
req.Header.Add("X-cons-id", cons_id)
req.Header.Add("X-timestamp", tstamp)
req.Header.Add("X-signature", X_signature)
req.Header.Add("user_key", User_key)
res, err := http.DefaultClient.Do(req)
if err != nil {
fmt.Println(err)
}
body, err := ioutil.ReadAll(res.Body)
if err != nil {
fmt.Println(err)
}
fmt.Println(string(body))
var resp_mentah Respon_MentahDTO
var resp Respon_DTO
json.Unmarshal([]byte(body), &resp_mentah)
resp_decrypt, _ := ResponseVclaim(string(resp_mentah.Response), string(cons_id+Secret_key+tstamp))
resp.MetaData = resp_mentah.MetaData
json.Unmarshal([]byte(resp_decrypt), &resp.Response)
return &resp
}