管理员
论坛积分
分
威望 点
贡献值 个
金币 枚
|
提供B2B的移动商务解决方案,通过图像识别技术,通过摄像头扫描直接查询和购买商品。
, v; G7 P) ?. F7 H0 i) L1.添加商品信息$ o$ z6 ^* U" d6 w
2.添加图片0 I5 I+ d; D# v" x* ]
3.查询所有产品
* }. C9 N. H4 ~$ m5 ?4.查询某个具体产品信息
3 N: n. o, P- A3 v5.删除某个产品
- b- ]3 i" [! q! Q6.删除图片7 ^% h! ?3 A; ? O3 `$ |8 z4 V
7.图像识别0 I7 ~, K8 X- ~$ c( R2 R
( N# Y& C; c: O% X" V; s图像识别API文档:https://www.juhe.cn/docs/api/id/117,申请后生成AppKey k0 S7 ] z3 D1 A# D% h% z' v
. x/ C, A G# C1 w" QPHP示例:, m* [, ^9 u, J6 r3 G/ H0 R+ P8 X
- <!--?php$ s7 c& C, b9 r1 c
- // +----------------------------------------------------------------------3 w6 e7 r+ K3 t1 F8 y# e! |) i
- // | JuhePHP [ NO ZUO NO DIE ]
4 o) S: g5 Z( S, K! @" c* e u - // +----------------------------------------------------------------------. d# ?! j! z$ z3 f1 n$ _
- // | Copyright (c) 2010-2015 http://juhe.cn All rights reserved.5 Q! U6 N, h$ h& x6 a4 l2 }
- // +----------------------------------------------------------------------, C+ F% j. g+ _
- // | Author: Juhedata <info@juhe.cn-->6 V' p) E$ _' d7 Q. P F
- // +----------------------------------------------------------------------7 _- e. s4 t5 j) E2 I
- , ?6 @4 n3 V0 S$ b! m& _* Y
- //----------------------------------
5 n4 U7 A- Y7 y0 x7 f' z1 j0 V5 Q - // 图像识别调用示例代码 - 聚合数据- h& \0 V& f/ E8 Y
- // 在线接口文档:http://www.juhe.cn/docs/1171 E: z7 I! ~* j+ ~5 K
- //----------------------------------! n3 }0 `9 B2 d# Q, W
- 1 k8 q3 a: \0 U# w
- header('Content-type:text/html;charset=utf-8');
5 h8 k" e# C* W/ A* I -
6 N+ Y; n4 y: i4 R! E4 d - 3 ?9 O' c0 p9 L' s
- //配置您申请的appkey9 L% i! Y# [- f9 r% Y
- $appkey = "*********************";4 X' r# a! i+ w Q
- + e; L- }& @7 ~! J
-
9 E0 B' n# c! d* O - 7 U# i+ i( ]0 a& R3 [. H) }" I* }5 {
-
( V" s# d( B$ I ]6 R - //************1.图像上传************( j4 g& ]4 T' ~- O- a
- $url = "http://japi.juhe.cn/image_recognition/upload";& b+ x+ k- r p0 u( R$ T( C
- $params = array(! l& o# x* T5 Y3 {
- "file" => "",//上传的单张图片
' f3 w3 w6 I& b - "key" => $appkey,//APP Key: _2 d- f" i: W; i
- "pname" => "",//包名8 Q5 u. K% K" S K3 f
- );9 L1 y$ m% p- q
- $paramstring = http_build_query($params);) @' }# ?3 Q. T5 n! X
- $content = juhecurl($url,$paramstring,1);
8 Y" }+ h0 c& u C" j" l - $result = json_decode($content,true);- U$ i! C5 g) H- v5 K2 Q5 h0 a' b
- if($result){
6 m: L: j, V7 U2 ? - if($result['error_code']=='0'){: z: V' ~9 h* q: z6 {" X0 i
- print_r($result);6 T+ h- H$ ^/ @2 X1 d
- }else{" T4 ?# ^8 ]% A1 _1 }* y
- echo $result['error_code'].":".$result['reason'];
W7 p9 J) I4 u( A7 B - }
# }0 F8 C( C% G6 ?- n& p+ D - }else{
4 u! T5 N+ ~+ Z' o/ k9 k! j - echo "请求失败";
- w6 d/ U7 ^! U# o. `3 b - }
$ c" R( d+ U, o4 K - //*************************************************** b* e# x& e: e; q3 J
-
( x* j) N m2 F - 1 m* P D: H" l- _6 D* T( B
-
# r' P$ i- X' e: `2 G) u+ K - 4 _3 G- t0 K9 w& H: }, K5 a2 {
- //************2.查寻上传图像信息************+ j# O. X8 A' R+ P! U3 O7 Z
- $url = "http://japi.juhe.cn/image_recognition/findAll";
3 u; f* Y9 h! ?. l9 x$ w7 M& D - $params = array(; H4 {4 G2 S* u9 V
- "key" => $appkey,//APP Key
& O+ {3 F3 D( @, F4 L - );1 b. d7 i4 a# u$ a' Q b/ p% u
- $paramstring = http_build_query($params);1 M- h6 F9 k( R5 g
- $content = juhecurl($url,$paramstring);7 ~& s5 c7 i' \! \
- $result = json_decode($content,true);
% s0 V6 M% d2 w - if($result){
9 p+ ^8 @6 Q) A% K& l. C - if($result['error_code']=='0'){
0 u3 d& S0 Y8 c |1 x - print_r($result);: W9 a' N6 k1 d$ A) ]; L
- }else{* n- v" o s- J. T! |# E9 g
- echo $result['error_code'].":".$result['reason'];4 q1 O( V+ i) x+ g" q# Z
- }
" b$ k8 k- p; z0 s6 A - }else{
* b- I7 _3 f$ ^, F( B2 G) I1 ^+ h - echo "请求失败";
; v# Y% H2 y7 P4 I! o! ]1 G - }& \. n, }+ \4 M3 L4 c
- //**************************************************1 [! |$ H1 ~: c- F2 e. G8 `6 C
-
/ u3 }! B- j9 }& ` Q1 A, x. V -
+ w( b! c8 _' Y( D - 4 U& ` T( u8 q( w# @$ q) |
-
7 N: f8 L+ Z8 k/ i - //************3.删除图像信息************
6 I& f$ L: y% Z8 Z - $url = "http://japi.juhe.cn/image_recognition/delete";1 k+ R+ E7 q7 T% G& X( `+ y
- $params = array(( y5 |( c+ [ b% `. ^) z
- "key" => $appkey,//APP Key: {% ?* P: M: E6 y
- "imageId" => "",//图片ID
0 P/ v Z4 @1 [, f - );
- x' I- x0 k/ v6 h, ~2 \# v b - $paramstring = http_build_query($params);1 s7 Z5 ~- [' @7 a$ {+ Y
- $content = juhecurl($url,$paramstring);
& x8 w, M5 y4 p( r( q& _& c - $result = json_decode($content,true);
: }" S: r7 }# R2 o& S0 x# O C - if($result){
# C* @. q$ O& h m9 m9 Q" S - if($result['error_code']=='0'){
- J! B& l) C0 d - print_r($result);
7 a9 X. m9 C( V - }else{
' k) ]- p: J6 V" _( \ - echo $result['error_code'].":".$result['reason'];( q" P: @& S. R2 C1 L$ r
- }* q: G+ @. R/ o3 P: v: e# X
- }else{
+ c( z, q1 t5 ? - echo "请求失败";
% P3 ^2 ]3 C2 N+ I! f8 V - }
O/ I2 v6 I% w; T# q - //**************************************************
: \5 Z/ T' N! C0 U# m( O -
. }: x: A0 h1 J( I -
; v7 E F3 D/ x* N: o - 7 ^, u/ g" \2 V" G& l. u
-
! h$ b% k B* g, n" s4 h - //************4.图像识别************
0 ^& x) N5 D: m7 s# @' a* x' g - $url = "http://japi.juhe.cn/image_recognition/check";
2 {6 o7 m4 @+ ~! e1 v8 t' ` - $params = array( u% I w7 s( r4 v2 [- {
- "file" => "",//上传的图片
$ V/ \& u, o% N' S f9 q, _ - "key" => $appkey,//APP Key
6 T0 v% V5 k( D: S - "pname" => "",//包名, A2 l# H' a* a: K5 X! J5 F
- "device_name" => "",//设备名称(如android OS或iphone OS)3 F, d/ a" H8 T/ y6 [
- "device_version" => "",//设备版本(如:4.0.3)( K0 s% i! R: q" K" ~ v
- "latitude" => "",//纬度4 g. d2 \% |2 v4 ?) u
- "longitude" => "",//经度/ \6 P$ ~% A4 }0 Q: K" P
- "uuid" => "",//设备id: m" z( U- ?! c" o, q
- "zone" => "",//请求地区3 M9 h5 q. O8 _0 v A7 z; N
- );- f: m0 q3 A/ e" N' R1 A! w
- $paramstring = http_build_query($params);
6 ^6 X! ~8 K1 g" c0 V3 _ - $content = juhecurl($url,$paramstring,1);
4 L$ F& z" t, ~, E3 }9 d - $result = json_decode($content,true);
$ v' X$ g1 V E5 O7 l/ j6 U* R3 w - if($result){" L* [7 ]9 I% |$ P4 @
- if($result['error_code']=='0'){* r2 T; G3 w, U; N# l
- print_r($result);( D' v6 V4 I: w" M& ^" m, t! a( `
- }else{
- X. r5 k/ d( J: E9 g7 l - echo $result['error_code'].":".$result['reason'];3 @' r* M8 G- R$ ^& P! R
- }
8 r2 N$ p! {: w- i - }else{: Q& R' ~; x* S/ e
- echo "请求失败";( ^1 @+ _. ~! w5 E
- }- b6 k2 V6 O! |" d2 U2 j
- //**************************************************
6 H, l7 `6 B- M0 Q6 P7 ?0 v - 5 {7 x$ b# I6 E' x
- 3 h. d, k N0 F4 E6 Y' @- e
- 4 C' G8 m+ F/ D+ q) D
- 1 t7 V# v- O8 t+ D( ?
- ( A& B9 q1 V' S$ W
- /**6 p0 |7 h4 Q ~: k5 e
- * 请求接口返回内容
* E4 W' }- ~3 F# a7 z - * @param string $url [请求的URL地址]' t. I! J# T" z/ w) T. I
- * @param string $params [请求的参数]
- @7 C7 H( w- P5 Y/ Z% X - * @param int $ipost [是否采用POST形式]
- ~" O# n; z) C% c2 ^5 d - * @return string
4 [9 Z8 I$ L/ p. V - */5 o! {0 U8 v. _, V1 t8 v6 g. N |
- function juhecurl($url,$params=false,$ispost=0){2 ^; j+ b) w# \" @
- $httpInfo = array(); A, e, O& D% T4 L* d' i
- $ch = curl_init();# x9 ]. B* }/ D7 P, h" g2 g1 t
- : Q# k- [' }# a3 j
- curl_setopt( $ch, CURLOPT_HTTP_VERSION , CURL_HTTP_VERSION_1_1 );
$ n4 y1 o- s- p2 v9 g: X - curl_setopt( $ch, CURLOPT_USERAGENT , 'JuheData' );
0 \& k2 C8 g9 T% ~ - curl_setopt( $ch, CURLOPT_CONNECTTIMEOUT , 60 );
( q$ J9 O0 E& P& [' P9 `3 O0 h - curl_setopt( $ch, CURLOPT_TIMEOUT , 60);
* ]$ C$ j3 U/ N' o6 ~* {4 {6 A - curl_setopt( $ch, CURLOPT_RETURNTRANSFER , true );* J' i9 U! F5 i+ j
- curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
j9 {7 \1 [+ }0 o* Q! k( R5 o - if( $ispost )& }3 Y3 j! ]7 X$ D
- {* ^8 u/ J( g! x" V+ R8 O
- curl_setopt( $ch , CURLOPT_POST , true );) p! B; u- y+ O* G$ _6 D
- curl_setopt( $ch , CURLOPT_POSTFIELDS , $params );
. }) I. i7 E ?2 B5 b M - curl_setopt( $ch , CURLOPT_URL , $url );
& T! W- @& D; Z( [* z" w - }: y3 q! T5 s/ q. A$ E. Z: G
- else6 f3 ^. J1 }3 s
- {
! h/ g; o& y1 l6 i0 d. ]6 T; p+ s - if($params){
5 |; @( R! c- ^* E1 l - curl_setopt( $ch , CURLOPT_URL , $url.'?'.$params );9 D0 i) v0 n( d
- }else{
6 ^; a7 c2 ^ n+ z! A1 t* Z6 n - curl_setopt( $ch , CURLOPT_URL , $url);
2 ]1 I: ]! x6 X - }2 `+ k4 O2 p0 \6 a2 W
- }& G7 R1 G5 M" I. m" \) @# q) m
- $response = curl_exec( $ch );
$ F5 w% N9 O) ]3 K - if ($response === FALSE) {
( p2 g; G, D- C- Q' v% \1 F1 U# j - //echo "cURL Error: " . curl_error($ch);' b3 e! T8 x! c3 C! G7 c1 W
- return false;
6 F/ T, p( p" L: Z4 F1 v - }* R) t3 @' E& b, W" n* w4 O
- $httpCode = curl_getinfo( $ch , CURLINFO_HTTP_CODE );
+ {9 f: ^% {0 m) G7 k - $httpInfo = array_merge( $httpInfo , curl_getinfo( $ch ) );8 b* C3 I- v" @/ u
- curl_close( $ch );
3 h2 F# k- {) i! d# D) {! v) G' B/ A, v - return $response;7 ?, S! _5 O: l4 ^. w- R, T
- }
复制代码 Q5 k2 w2 m" i* c6 r2 f
9 y9 O. M5 h- V |
|