管理员
论坛积分
分
威望 点
贡献值 个
金币 枚
|
提供B2B的移动商务解决方案,通过图像识别技术,通过摄像头扫描直接查询和购买商品。( {+ t& Z/ S5 {0 k* C2 a
1.添加商品信息
9 h( v& @! X8 Q2.添加图片
, O4 @0 _; Q3 r. ]' e3.查询所有产品. ~1 g3 A- I( t5 u( c
4.查询某个具体产品信息
3 g! z7 M0 }0 V& P5.删除某个产品
& ]+ r8 Y- s8 ^) U; T6.删除图片$ v; Z# G; s) Q( S1 ~ \( s% j
7.图像识别
% v; H+ D# \4 ?; [& Y- k( w: Y2 z4 k2 s) F
图像识别API文档:https://www.juhe.cn/docs/api/id/117,申请后生成AppKey6 N8 b; n6 j: W' c5 [; j
# [4 L3 ]2 ~5 t* y6 d5 cPHP示例:3 M4 H; [8 M- k3 v# q) M3 r! ]* B
- <!--?php6 M5 \4 M2 b# J* x+ H
- // +----------------------------------------------------------------------
, y7 K" I5 f5 L N$ W. W. e, f- d - // | JuhePHP [ NO ZUO NO DIE ]
1 T! N6 W- X7 B5 `( Z. Z - // +----------------------------------------------------------------------
" f! G( z* z- D; R - // | Copyright (c) 2010-2015 http://juhe.cn All rights reserved.$ t2 X% k) ]9 w4 t
- // +----------------------------------------------------------------------! x; ]; N4 n+ ~7 M
- // | Author: Juhedata <info@juhe.cn-->
2 E+ {, X f2 \) C - // +----------------------------------------------------------------------( s; u& B. W( D4 t9 v7 N5 r! J
-
6 |* f" O2 t; o* u: {0 w4 H - //----------------------------------
4 h H: Q. ^# Q# }9 P - // 图像识别调用示例代码 - 聚合数据8 h, g) E/ ~) c7 Z
- // 在线接口文档:http://www.juhe.cn/docs/1179 Y2 Y- O2 Z* e
- //----------------------------------
8 t. \, a Q- ?. l1 N - 6 z' \, c* f) ]2 z$ |8 Z
- header('Content-type:text/html;charset=utf-8');
$ ?; m# a0 ~$ p; R. h0 u -
) ?3 _. C( A: l6 w3 i- g" m& F -
4 K0 \8 B) w* w+ z - //配置您申请的appkey
0 f; R9 h& A# q - $appkey = "*********************";
( q+ M: n/ Y+ A. }% M - & H ~9 A9 b2 ^2 q1 f% l
-
9 U& r3 o9 I; e' T, X6 j: m - ' R; h4 T# U# A- k
- 1 P' J5 v# m7 r* w5 z+ x+ W
- //************1.图像上传************
$ x% M% l3 C/ j" w# \ - $url = "http://japi.juhe.cn/image_recognition/upload";9 v$ p W& y- V7 \6 k1 k" F' m
- $params = array(
6 Z% q e3 ?* R0 t/ K/ [0 c# `( N - "file" => "",//上传的单张图片
9 M% x* W% a% g& g - "key" => $appkey,//APP Key
5 |! b9 O2 s2 `- K1 M0 e* X$ x - "pname" => "",//包名
1 H2 \8 X+ C% w! Z# ?& `6 Z; J - );5 Y2 @' Y, i" L' K
- $paramstring = http_build_query($params);7 o8 X0 G2 j# w6 g4 N
- $content = juhecurl($url,$paramstring,1);
! S3 Q5 D. Z K1 R6 @+ x - $result = json_decode($content,true);3 `4 I+ c8 R3 k2 \0 r; H
- if($result){: C9 b8 l$ x& F# f
- if($result['error_code']=='0'){
d" D' \' F; _8 F0 l4 j; s - print_r($result);7 A9 N, F6 `: P
- }else{
3 R: D/ k0 a* J; I - echo $result['error_code'].":".$result['reason']; M& B$ I) H& Y2 B6 k. S4 P
- }
; R3 _. M+ l5 t9 O - }else{
3 ` o, A! m" Y6 c2 z; | - echo "请求失败";
- ~. m' D* g6 x2 E5 I - }
. B# o4 Y; H' p% C+ W) _4 P+ J5 ^ - //**************************************************, A0 F- f4 i$ Y% k
-
3 G: T+ N3 X9 }" o) w -
$ p/ o! a# G9 M- ]3 w9 r5 d -
! _( J* F$ z8 ?5 z8 p2 e" h+ w -
. Z! m( f% h' F: x2 d' W* u6 ?: C - //************2.查寻上传图像信息************
; L: e( O' B/ |) [4 Z - $url = "http://japi.juhe.cn/image_recognition/findAll";5 ]+ r% [) J5 w$ G
- $params = array(4 s' R7 n: v( |4 M0 j1 }) k, i
- "key" => $appkey,//APP Key
' f% E: K) K t D" {7 ` - );
+ |+ V- _! M- I" n. M - $paramstring = http_build_query($params);
( {/ Y# v( d- i- L0 b: N - $content = juhecurl($url,$paramstring);$ M4 C& H4 [! Y7 I! S) i5 j1 s7 S
- $result = json_decode($content,true);
8 Q9 n& T C4 \1 o( K: M - if($result){4 v/ Q; `+ _2 F9 x" G( r3 f; o
- if($result['error_code']=='0'){; O3 I F5 f8 ^0 p( I4 c
- print_r($result);1 n0 m. T# u5 T4 ~+ G* u
- }else{
% ^. j! S7 ?1 V* t& c( r# V - echo $result['error_code'].":".$result['reason'];0 t2 p2 s! f3 b1 M1 u
- }
* [5 C& y, X# y9 m1 W8 `* @ - }else{* x) J) E5 O C
- echo "请求失败";" [- O9 ^% l. @
- }* @. i5 G& ]4 J C# U0 }8 Q* b: A
- //**************************************************
7 @, U9 }/ [6 |9 d8 w' @- ? -
0 b9 u3 V5 C. ^% P4 _) _) n -
, Q) G& R0 d1 g E - & j* }9 K. d! b8 J, o
- ' d* _$ T7 _ o, ~
- //************3.删除图像信息************
9 _8 U8 f% K9 U+ Y# m/ H5 S9 a - $url = "http://japi.juhe.cn/image_recognition/delete";
8 A0 O5 N' I1 Y% z; ^7 \) } - $params = array(( C1 A2 y |" z) y
- "key" => $appkey,//APP Key
$ x, r, K6 m* d+ q" ^ - "imageId" => "",//图片ID: i7 Y0 ]6 s! M. x! G
- );
- L$ \1 `. |) D; F. b+ E - $paramstring = http_build_query($params);
3 w# S- @+ u$ v* c: e3 S; L - $content = juhecurl($url,$paramstring);, M8 s, q C3 v. E% N' d
- $result = json_decode($content,true);
B4 A. w& S8 W; u4 ` - if($result){' n9 O( l: f: M- Q4 N, l+ S4 {
- if($result['error_code']=='0'){
9 z& s& e4 g" \) p" {7 E - print_r($result);( ^; u% f3 @2 ]2 j8 y" f
- }else{
$ d3 F7 J# a. K0 K3 ~ - echo $result['error_code'].":".$result['reason'];- m+ W; X# [, Z* j6 T/ _
- }- K: ^ o6 ]! k" k) \6 K
- }else{+ L# A/ H7 p' F- t: L
- echo "请求失败"; S1 |+ q/ s9 T2 N$ U
- }
0 I9 s( d' R) B3 C3 c - //**************************************************
: u$ N8 D! e0 M4 B) ^" |5 t - ! c5 n4 o' N) T5 i- O
-
; N4 h) k3 O& j6 K( a5 p. d -
/ K- |3 C( O4 s# P: _" I8 Y -
. R& x+ n9 c/ F/ b - //************4.图像识别************
. L0 u) ^) g' w6 m - $url = "http://japi.juhe.cn/image_recognition/check";% `: o: O" i$ b0 Q! q( D
- $params = array(' Y4 n& {/ e5 B. u4 H
- "file" => "",//上传的图片
0 E! T$ p% y) ?# Y6 ^8 E - "key" => $appkey,//APP Key
' J2 I+ @+ n8 c7 Y5 C- D! Y - "pname" => "",//包名
D% k9 `, R6 y& r; l# N) ^ - "device_name" => "",//设备名称(如android OS或iphone OS)8 o6 L6 F2 w, V' [! T# y
- "device_version" => "",//设备版本(如:4.0.3)
4 c R9 f- g, ` - "latitude" => "",//纬度
; T2 ^. z" q3 f8 B5 C1 J, h - "longitude" => "",//经度# a* f" F: w; [. _9 b5 e* i3 [" Z
- "uuid" => "",//设备id# @) c/ D0 O; J- Q: ?
- "zone" => "",//请求地区
/ O+ ^: a! ~3 `+ D6 T3 q* e4 n - );. x/ O" w" g# O5 |
- $paramstring = http_build_query($params);4 g5 y+ x0 T7 H. X/ i9 D
- $content = juhecurl($url,$paramstring,1);
* s: t+ t: r1 N# c" v$ y - $result = json_decode($content,true);/ M/ X& ]- C) J( ?5 D
- if($result){/ Q& d# a2 B% V! a2 F" A0 a& x0 @0 N
- if($result['error_code']=='0'){; [2 Z4 ?$ B% ?* s9 q Q9 t% ^
- print_r($result);
6 N7 J0 g5 z/ A. Z. M+ D/ R j# { - }else{0 w% [' n: N- y$ T, K
- echo $result['error_code'].":".$result['reason'];- q' r- x2 R/ J( C2 T
- } [7 G/ j0 y7 N; C6 `+ |. h
- }else{% l, [# i/ C- z$ K- y
- echo "请求失败";+ }- C2 Q3 V% C$ E3 @, I1 \# Z
- }' N7 N( p6 I! K, ~% a# P
- //**************************************************
* k8 G( c0 f* ` - 4 P/ y/ M5 u+ b+ ~ }' ^
- # l* A; I2 d" h! K" O0 v( F9 l, W
-
, f. @& Q( X( S* v) z) R% n" D - % ?3 N" e5 V: ?6 L7 S9 c$ J
- 6 O" ?- |# ?$ _# s+ M8 f
- /**
! O. U w# O1 F' H( D - * 请求接口返回内容
! {0 ?+ P+ S$ v0 j5 O - * @param string $url [请求的URL地址]/ V# R5 |; g2 c( ]& `
- * @param string $params [请求的参数]
- t: U7 C3 L4 t - * @param int $ipost [是否采用POST形式]
% {7 O4 l6 K, h2 _! ~6 \; K - * @return string2 s" A4 }( S R/ A1 }# B `
- */
: i, e) o- |8 s6 v. M - function juhecurl($url,$params=false,$ispost=0){
" R2 u5 U$ s& ]+ h5 a6 e - $httpInfo = array();
. k; Z- }/ ^+ e - $ch = curl_init();1 w' Y2 t( r4 m+ M
- 8 r G- F4 C. i3 g. a0 n
- curl_setopt( $ch, CURLOPT_HTTP_VERSION , CURL_HTTP_VERSION_1_1 );5 g! w9 T6 z" Y- |
- curl_setopt( $ch, CURLOPT_USERAGENT , 'JuheData' );; Z0 l( z5 h) f5 q# q
- curl_setopt( $ch, CURLOPT_CONNECTTIMEOUT , 60 );1 H# g, C4 R3 m4 _ p9 u
- curl_setopt( $ch, CURLOPT_TIMEOUT , 60);; v% n5 [9 s' p
- curl_setopt( $ch, CURLOPT_RETURNTRANSFER , true );
' O! a6 L9 o+ A- f/ N( t - curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);6 f/ t. h: M* J+ X
- if( $ispost )
4 E4 i" {2 B3 s( z$ C+ Q% H. Q - {
+ ^, n, p+ X z" @& \ - curl_setopt( $ch , CURLOPT_POST , true );
$ z( |4 k; a4 i3 ~ - curl_setopt( $ch , CURLOPT_POSTFIELDS , $params );2 D: r0 x6 u$ |7 O% d( L
- curl_setopt( $ch , CURLOPT_URL , $url );
1 y2 X8 p6 k# } u! p% }/ o# r& r - }* L/ J; x# h( I+ o" f
- else; ]6 \; ?: `1 H d4 [4 c9 A& u
- {
" X- n& |1 `2 S* B% a) L4 L! x% _ - if($params){
2 l% R# G% M* V0 s# ^ - curl_setopt( $ch , CURLOPT_URL , $url.'?'.$params );4 g5 Z- S: T3 r- Z# R2 v
- }else{$ x- N7 M' r, L# ]! u
- curl_setopt( $ch , CURLOPT_URL , $url);; O# ]4 Q3 d9 d( F
- }
1 D o$ A; g$ n7 K' }( n- Q - }
* G- N. |& M; S P1 Y; z! Z - $response = curl_exec( $ch );' a) F! l4 S5 @6 N: W5 V
- if ($response === FALSE) {( ]: j: l0 V: Q L4 W4 Y' t
- //echo "cURL Error: " . curl_error($ch);9 V0 E+ k3 }: F- ^' y
- return false;& }3 |9 a" ^7 }& C+ o0 ]
- }0 ~7 z& W5 y$ p8 b- ?' t
- $httpCode = curl_getinfo( $ch , CURLINFO_HTTP_CODE );7 o7 g" a) j; I2 K
- $httpInfo = array_merge( $httpInfo , curl_getinfo( $ch ) );) y1 }8 G& w; D9 j# T o
- curl_close( $ch );
& R( r; M/ b6 s+ h1 d! } - return $response;& V- v2 m, {& w( C8 P; v1 M
- }
复制代码
% w D8 {* A, R( L% l7 M0 ^# h4 x( m
|
|